env-vars-config

Crates.ioenv-vars-config
lib.rsenv-vars-config
version0.5.3
created_at2025-03-07 14:38:03.56369+00
updated_at2025-06-24 00:55:48.026293+00
descriptionA simple lib for configuring your applications via environment variables
homepage
repositoryhttps://github.com/NikSneMC/env-vars-config
max_upload_size
id1583137
size21,450
NikSne (NikSneMC)

documentation

https://docs.rs/env-vars-config

README

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::{net::SocketAddr, str::FromStr as _};

use env_vars_config::{env_vars_config, set_env_only};

env_vars_config! {
    SERVER_ADDRESS: SocketAddr = SocketAddr::from_str("0.0.0.0:8080").expect("this is a valid SocketAddr"),
    WORKERS_COUNT: i32 = 32,
    OTEL_SERVICE_NAME: String = "test-service",
}

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

    println!("server address: {}", config::SERVER_ADDRESS.clone());
    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): {}",
        std::env::var("OTEL_SERVICE_NAME").unwrap()
    );

    config::test_values();
}

Commit count: 19

cargo fmt