salak

A layered configuration loader with zero-boilerplate configuration management.

Crates.io Crates.io Documentation dependency status License Actions Status

  1. About
  2. Features
  3. Placeholder
  4. Key Convension
  5. Cargo Features
    1. Default features
    2. Optional features
  6. Quick Example

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.

Placeholder

Key Convension

Cargo Features

Default features

  1. enable_log, enable log record if enabled.
  2. enable_toml, enable toml support.
  3. enable_derive, enable auto derive [FromEnvironment] for struts.

Optional features

  1. enable_clap, enable default command line arguments parsing by clap.
  2. enable_yaml, enable yaml support.
  3. enable_rand, enable random value support.

Quick Example

```rust use salak::*;

[derive(FromEnvironment, Debug)]

pub struct SslConfig { key: String, pem: String, }

[derive(FromEnvironment, Debug)]

[salak(prefix = "database")]

pub struct DatabaseConfig { url: String, #[salak(default = "salak")] username: String, password: Option, description: String, #[salak(name="ssl")] ssl_config: Option,
}

std::env::setvar("database.url", "localhost:5432"); std::env::setvar("database.description", "\$\{Hello\}"); let env = Salak::new() .withdefaultargs(autoreadsysargsparam!()) // This line need enable feature enable_clap. .build();

match env.load_config::() { Ok(val) => println!("{:?}", val), Err(e) => println!("{}", e), }

// Output: DatabaseConfig { // url: "localhost:5432", // username: "salak", // password: None, // description: "${Hello}", // ssl_config: None, // } ```