Created
June 5, 2019 16:30
-
-
Save deg4uss3r/aa61fabe1ee257d736677f419214ee07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! The most simplest exaples of how to use confy | |
extern crate confy; | |
#[macro_use] | |
extern crate serde_derive; | |
use std::io; | |
#[derive(Debug, Serialize, Deserialize)] | |
struct ConfyConfig { | |
name: Option<String>, | |
comfy: bool, | |
foo: i64, | |
} | |
impl Default for ConfyConfig { | |
fn default() -> Self { | |
ConfyConfig { | |
name: Some("Unknown".to_string()), | |
comfy: true, | |
foo: 42, | |
} | |
} | |
} | |
fn main() -> Result<(), io::Error> { | |
let cfg: ConfyConfig = confy::load("confy_simple_app")?; | |
match &cfg.name { | |
Some(e) => println!("Got name {}!", &e), | |
None => panic!("Error: did not supply a name value"), | |
} | |
println!("{:#?}", &cfg); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment