Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. //! The most simplest exaples of how to use confy
  2.  
  3. extern crate confy;
  4.  
  5. #[macro_use]
  6. extern crate serde_derive;
  7.  
  8. use std::io;
  9.  
  10. #[derive(Debug, Serialize, Deserialize)]
  11. struct ConfyConfig {
  12. name: Option<String>,
  13. comfy: bool,
  14. foo: i64,
  15. }
  16.  
  17. impl Default for ConfyConfig {
  18. fn default() -> Self {
  19. ConfyConfig {
  20. name: Some("Unknown".to_string()),
  21. comfy: true,
  22. foo: 42,
  23. }
  24. }
  25. }
  26.  
  27. fn main() -> Result<(), io::Error> {
  28. let cfg: ConfyConfig = confy::load("confy_simple_app")?;
  29.  
  30. match &cfg.name {
  31. Some(e) => println!("Got name {}!", &e),
  32. None => panic!("Error: did not supply a name value"),
  33. }
  34.  
  35. println!("{:#?}", &cfg);
  36. Ok(())
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement