3 unstable releases

Uses old Rust 2015

0.1.1 Jan 20, 2018
0.1.0 Jan 20, 2018
0.0.1 Nov 25, 2017

#825 in Configuration

Download history 286/week @ 2023-12-18 93/week @ 2023-12-25 122/week @ 2024-01-01 131/week @ 2024-01-08 210/week @ 2024-01-15 542/week @ 2024-01-22 647/week @ 2024-01-29 637/week @ 2024-02-05 262/week @ 2024-02-12 264/week @ 2024-02-19 529/week @ 2024-02-26 541/week @ 2024-03-04 324/week @ 2024-03-11 263/week @ 2024-03-18 324/week @ 2024-03-25 332/week @ 2024-04-01

1,274 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

28KB
627 lines

Configuration management.

This crate is intended to automatically bridge the gap from envionmental configuration into your project. By deriving the Configure trait for your configuration, you can get an automatic system for managing your configuration at runtime.

Deriving Configure

This library provides a custom derive which lets you derive the Configure trait. It requires that your type implement Deserialize.

We recommend that you implement configuration using these steps:

  1. Implement Default for your type, which provides the default values for each configuration field.
  2. Derive both Deserialize and Configure for your type. Use the #[serde(default)] attribute to fall back to the default implementation when the configurable values are not set.

For example:

#[macro_use]
extern crate configure;
extern crate serde;
#[macro_use]
extern crate serde_derive;

use std::net::SocketAddr;
use std::path::PathBuf;

#[derive(Deserialize, Configure)]
#[serde(default)]
pub struct Config {
    addr: SocketAddr,
    tls_cert: Option<PathBuf>,
}

impl Default for Config {
    fn default() -> Config {
        Config {
            addr: "127.0.0.1:7878".parse().unwrap(),
            tls_cert: None,
        }
    }
}

With this code, you can call Config::generate to pull you configuration from the environment, falling back to these default values if the end user has not set custom configuration for it.

Dependencies

~3MB
~60K SLoC