[][src]Crate confy

Zero-boilerplate configuration management

Why?

There are a lot of different requirements when selecting, loading and writing a config, depending on the operating system and other environment factors.

In many applications this burden is left to you, the developer of an application, to figure out where to place the configuration files.

This is where confy comes in.

Idea

confy takes care of figuring out operating system specific and environment paths before reading and writing a configuration.

It gives you easy access to a configuration file which is mirrored into a Rust struct via serde. This way you only need to worry about the layout of your configuration, not where and how to store it.

confy uses the Default trait in Rust to automatically create a new configuration, if none is available to read from yet. This means that you can simply assume your application to have a configuration, which will be created with default values of your choosing, without requiring any special logic to handle creation.

#[derive(Serialize, Deserialize)]
struct MyConfig {
    version: u8,
    api_key: String,
}

/// `MyConfig` implements `Default`
impl ::std::default::Default for MyConfig {
    fn default() -> Self { Self { version: 0, api_key: "".into() } }
}

fn main() -> Result<(), ::std::io::Error> {
    let cfg = confy::load("my-app-name")?;
}

Updating the configuration is then done via the store function.

Functions

load

Load an application configuration from disk

store

Save changes made to a configuration object