Rust Crates.io Crates.io docs.rs

LayeredConf

Yet Another Config Package

Future

Hopefully this one will be useful to someone. Incoming features: - More Documentation - Features

Features

Quick Example

Add layeredconf, clap, and serde to your Cargo.toml

toml [dependencies] layeredconf = "0.2.1" clap = "3.0.0-beta.5" serde = { version = "1.0", features = ["derive"] }

Define your config

```rust,ignore use layeredconf::{Builder, Format, LayeredConf, Source}; use serde::Deserialize;

[derive(LayeredConf, Deserialize)]

struct Config { /// Will also load this config file #[layered(load_config)] #[clap(long)] config: Option,

/// Required to be set in at least one Layer (config file, command line, etc.)
#[clap(long)]
name: String,

/// Optional field
#[clap(long)]
input: Option<String>,

/// Defaulted field
#[layered(default)]
#[clap(long)]
number: u32,

}

fn main() -> anyhow::Result<()> { let config: Config = Builder)::new() .newlayer(Source::OptionalFile { path: "/etc/myapp/config.yaml", format: Format::Auto, }) .newlayer(Source::File { path: "relative/config.yaml", format: Format::Auto, }) .newlayer(Source::Arguments) .solidify()?;

// Use config in your application

} ```