Twelf is a configuration solution for Rust including 12-Factor support. It is designed with
Layers in order to configure different sources and formats to build your configuration. The main goal is to be very simple using the proc macrotwelf::config.
For now it supports :
#[serde(default = ...)] coming from serde)TOML, YAML, JSON, DHALL, INI filesHashMap structure with MY_VARIABLE="mykey=myvalue,mykey2=myvalue2" and also array like MY_VARIABLE=first,second thanks to envy.twelf@1.8 version)```rust,no_run use twelf::{config, Layer};
struct Conf { test: String, another: usize, }
// Init configuration with layers, each layers override only existing fields let config = Conf::withlayers(&[ Layer::Json("conf.json".into()), Layer::Env(Some("PREFIX".to_string())) ]).unwrap(); ```
```rust,compile_fail use twelf::{config, Layer};
struct Conf { /// Here is an example of documentation which is displayed in clap test: String, another: usize, }
// Will generate global arguments for each of your fields inside your configuration struct let app = clap::Command::new("test").args(&Conf::clap_args());
// Init configuration with layers, each layers override only existing fields let config = Conf::withlayers(&[ Layer::Json("conf.json".into()), Layer::Env(Some("PREFIX".tostring())), Layer::Clap(app.getmatches().clone()) ]).unwrap();
// ... your application code ```
Check here for more examples.
Twelf supports crate features, if you only want support for json, env and toml then you just have to add this to your Cargo.toml
toml
twelf = { version = "0.3", default-features = false, features = ["json", "toml", "env"] }
Default features are ["env", "clap"]
Feel free to contribute to the twelf project.
Enable all features when testing changes to the crate:
console
cargo test --all-features
config-rs don't have clap support and it didn't use any proc-macros if you're not very fan of proc-macros.