Crate configure [] [src]

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:

Be careful when using this code, it's not being tested!
#[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.

Modules

source

Controlling the source of configuration.

Macros

use_config_from
use_default_config

Structs

DeserializeError

Error when a Serializer or Deserializer trait object fails.

Traits

Configure

A configuration struct which can be generated from the environment.