#config-env #env-vars-config

bin+lib env-vars-config

A simple lib for configuring your applications via environment variables

5 releases (3 breaking)

new 0.5.2 Apr 17, 2025
0.5.1 Apr 17, 2025
0.4.2 Apr 17, 2025
0.3.1 Mar 23, 2025
0.1.0 Mar 7, 2025

#435 in Configuration

Download history 126/week @ 2025-03-07 132/week @ 2025-03-14 232/week @ 2025-03-21 44/week @ 2025-03-28 30/week @ 2025-04-04 608/week @ 2025-04-11

928 downloads per month

MIT/Apache

9KB
101 lines

env-vars-config

A simple lib for configuring your applications via environment variables.

Build status Latest version Documentation License

Minimum supported rustc

1.80.0+

This version is explicitly tested in CI and may be bumped in any release as needed. Maintaining compatibility with older compilers is a priority though, so the bar for bumping the minimum supported version is set very high. Any changes to the supported minimum version will be called out in the release notes.

Usage

[dependencies]
env-vars-config = "0.5"
use std::env;

use env_vars_config::{env_vars_config, set_env_only};

env_vars_config! {
    SERVER_ADDRESS: String = "0.0.0.0:8080",
    WORKERS_COUNT: i32 = 32,
    OTEL_SERVICE_NAME: String = "test-service",
}

fn main() {
    config::init();

    println!("server address: {}", config::SERVER_ADDRESS.as_str());
    println!("workers count: {}", config::WORKERS_COUNT.clone());
    println!("otel service name: {}", config::OTEL_SERVICE_NAME.clone());

    unsafe {
        use config::OTEL_SERVICE_NAME;
        set_env_only!(OTEL_SERVICE_NAME);
    }

    println!(
        "otel service name (from env): {}",
        env::var("OTEL_SERVICE_NAME").unwrap()
    );

    config::test_values();
}

Dependencies

~90KB