pub fn run<P: AsRef<Path>, Q: AsRef<Path>>(
input: P,
output: Q,
options: ConvertOptions,
config_adapter: &impl ConfigPort,
persist_adapter: &impl PersistPort,
) -> Result<ConvertResult>Expand description
Converts a TOML configuration file to JSON.
This function loads a TOML configuration, validates it, and writes the validated theme to a JSON file. The conversion is atomic — if any step fails, no output file is created.
§Arguments
input— Path to the input TOML fileoutput— Path where the JSON output will be writtenoptions— Configuration for conversion behaviorconfig_adapter— Adapter for loading TOML configurationpersist_adapter— Adapter for writing JSON output
§Returns
Ok(ConvertResult)— Conversion succeededErr(FernError)— Conversion failed
§Errors
Returns an error if:
- The input file cannot be read
- TOML parsing fails
- Validation fails
- The output file cannot be written
§Example
ⓘ
use fernctl::commands::convert::{run, ConvertOptions};
use fernctl::adapters::{TomlConfigAdapter, FileSystemAdapter};
use std::path::Path;
let config_adapter = TomlConfigAdapter::new();
let persist_adapter = FileSystemAdapter::new();
let result = run(
Path::new("~/.config/fern/config.toml"),
Path::new("~/.config/fern/config.json"),
ConvertOptions::default(),
&config_adapter,
&persist_adapter,
)?;
println!("Conversion complete with {} warnings", result.warnings.len());§Atomicity Guarantee
This function guarantees that either:
- The output file is completely written with valid JSON, OR
- No changes are made to the output file
This is achieved by validating completely before writing, so partial or corrupted output is never possible.