Skip to main content

save

Function save 

Source
pub fn save<P, T>(path: P, config: T, file_type: FileType) -> Result<()>
where P: AsRef<Path>, T: Serialize,
Expand description

Save the current config to a TOML or JSON file.

The file_type must match the file extension inferred from path. .jsonc paths are written as standard JSON and therefore require FileType::JSON.

use cloudiful_config::{FileType, save};
use serde::Serialize;

#[derive(Serialize)]
struct AppConfig {
    port: u16,
}

let path = std::env::temp_dir().join("config-crate-save-example.toml");
save(&path, AppConfig { port: 8080 }, FileType::TOML).unwrap();