1 stable release

1.0.0 Oct 21, 2024

#735 in Configuration

Download history 3/week @ 2024-11-27 53/week @ 2024-12-04 100/week @ 2024-12-11 14/week @ 2024-12-18 42/week @ 2025-01-08 59/week @ 2025-01-15 14/week @ 2025-01-22 62/week @ 2025-02-05 9/week @ 2025-02-12 34/week @ 2025-02-19 32/week @ 2025-02-26 17/week @ 2025-03-05 83/week @ 2025-03-12

166 downloads per month
Used in freedom-api

MIT license

14KB
256 lines

Freedom Config

Utilities for creating an ATLAS Freedom configuration

Usage

The freedom-config API provides an easy to use builder type for constructing the configuration, which can be invoked with the following:

use freedom_config::{Config, Test};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::builder()
        .environment(Test)
        .key("my_key")
        .secret("my_secret")
        .build()?;
        
    println!("{:?}", config);
    Ok(())
}

The builder can also be used to source these items from the environment:

use freedom_config::Config;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    std::env::set_var(Config::ATLAS_ENV_VAR, "Test");
    std::env::set_var(Config::ATLAS_KEY_VAR, "my_key");
    std::env::set_var(Config::ATLAS_SECRET_VAR, "my_secret");

    let config = Config::builder()
        .environment_from_env()?
        .key_from_env()?
        .secret_from_env()?
        .build()?;
        
    println!("{:?}", config);
    
    Ok(())
}

Since this is fairly common, there is also a shorthand for constructing the config entirely from environment variables

use freedom_config::Config;

fn main() {
    let config = Config::from_env();
}

Dependencies

~2–3MB
~54K SLoC