rust-cli / confy

🛋 Zero-boilerplate configuration management in Rust
Other
907 stars 61 forks source link

confy section not clear and leads to compilation errors #61

Open Masber opened 2 years ago

Masber commented 2 years ago

confy requires serde for serialization and deserialization and the documentaion is not clear about this. Also confy will fail in file is missing my_app so Default trait was also added.

Add confy and serde to your cargo.toml

confy = "0.4.0"
serde = { version = "1.0", features = ["derive"] }

Add Default trait to generate a file with default values if missing.

use serde::{Serialize, Deserialize};

#[derive(Default, Debug, Serialize, Deserialize)]
struct MyConfig {
    name: String,
    comfy: bool,
    foo: i64,
}

fn main() -> Result<(), io::Error> {
    let cfg: MyConfig = confy::load("my_app")?;
    println!("{:#?}", cfg);
    Ok(())
}