salak-0.8.0 has been yanked.
salak
A layered configuration loader with zero-boilerplate configuration management.
About
salak is a rust version of layered configuration loader inspired by
spring-boot.
salak provide an [Environment] structure which load properties from various [PropertySource]s.
Any structure which impmement [FromEnvironment] can get from [Environment] by a key.
Feature enable_derive provide rust attributes for auto derive [FromEnvironment].
Features
Below are a few of the features which salak supports.
- Auto mapping properties into configuration struct.
#[salak(default="value")]set default value.#[salak(name="key")]rename property key.#[salak(prefix="salak.database")]set prefix.
- ** Supports load properties from various sources **
- Support following random property key.
random.u8random.u16random.u32random.i8random.i16random.i32random.i64
- Load properties from command line arguments.
- Load properties from system environment.
- Load properties from toml config file.
- Load properties from yaml config file.
- Easy to add a new property source.
- Support following random property key.
- Supports profile(develop/production) based configuration.
- Supports placeholder resolve.
- Supports reload configurations.
Placeholder
${key:default}means get value ofkey, if not exists then returndefault.${key}means get value ofkey, if not exists then returnPropertyError::NotFound(_).\$\{key\}means escape to${key}.
Key Convension
a.b.cis a normal key separated by dot(.).a.b[0],a.b[1],a.b[2]... is a group of keys with arrays.
Cargo Features
Default features
enable_log, enable log record if enabled.enable_toml, enable toml support.enable_derive, enable auto derive [FromEnvironment] for struts.
Optional features
enable_pico, enable default command line arguments parsing bypico-args.enable_clap, enable default command line arguments parsing byclap.enable_yaml, enable yaml support.enable_rand, enable random value support.
Quick Example
use *;
set_var;
set_var;
let env = new
.with_default_args // This line need enable feature `enable_clap`.
.build;
match env.
// Output: DatabaseConfig {
// url: "localhost:5432",
// username: "salak",
// password: None,
// description: "${Hello}",
// ssl_config: None,
// }
Salak Factory
salak_factory is out-of-box crate for using well known components, such as redis, postgresql, etc.
let env = new.build;
let redis_pool = env..unwrap;
let redis_conn = redis_pool.get.unwrap;
let _: u64 = redis_conn.set.unwrap;
/// Use redis_conn.