Using config files

Dealing with configurations can be annoyingespecially if you support multiple operating systemswhich all have their own placesfor short- and long-term files.

There are multiple solutions to this,some being more low-level than others.

The easiest crate to use for this is confy.It asks you for the name of your applicationand requires you to specify the config layoutvia a struct (that is Serialize, Deserialize)and it will figure out the rest!

  1. #[derive(Debug, Serialize, Deserialize)]
  2. struct MyConfig {
  3. name: String,
  4. comfy: bool,
  5. foo: i64,
  6. }
  7. fn main() -> Result<(), io::Error> {
  8. let cfg: MyConfig = confy::load("my_app")?;
  9. println!("{:#?}", cfg);
  10. Ok(())
  11. }

This is incredibly easy to usefor which you of course surrender configurability.But if a simple config is all you want,this crate might be for you!

Configuration environments

TODO

  • Evaluate crates that exist
  • Cli-args + multiple configs + env variables
  • Can configure do all this? Is there a nice wrapper around it?