5 releases (3 breaking)

0.4.0 Mar 13, 2020
0.3.1 Dec 6, 2018
0.3.0 May 28, 2018
0.2.0 Mar 8, 2016
0.1.0 Mar 8, 2016
Download history 569/week @ 2020-12-25 513/week @ 2021-01-01 722/week @ 2021-01-08 639/week @ 2021-01-15 730/week @ 2021-01-22 458/week @ 2021-01-29 744/week @ 2021-02-05 422/week @ 2021-02-12 589/week @ 2021-02-19 569/week @ 2021-02-26 632/week @ 2021-03-05 614/week @ 2021-03-12 580/week @ 2021-03-19 810/week @ 2021-03-26 605/week @ 2021-04-02 658/week @ 2021-04-09

2,523 downloads per month
Used in 43 crates (42 directly)

MIT/X11 OR Apache-2.0

11KB
99 lines

confy

Chat with us: Discord

Zero-boilerplate configuration management.

Focus on storing the right data, instead of worrying about how to store it.

#[macro_use]
extern crate serde_derive;

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

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

lib.rs:

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.

# use serde_derive::{Serialize, Deserialize};

#[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<(), confy::ConfyError> {
    let cfg = confy::load("my-app-name")?;
    Ok(())
}

Updating the configuration is then done via the store function.

Dependencies

~435–640KB
~13K SLoC