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!
#[derive(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(())
}
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?