4 releases

0.1.5 Feb 2, 2021
0.1.3 Jan 19, 2021
0.1.1 Jan 19, 2021
0.1.0 Jan 19, 2021

#5 in #var

Download history 54/week @ 2024-04-01 15/week @ 2024-04-08 5/week @ 2024-04-22 6/week @ 2024-04-29 3/week @ 2024-05-20 28/week @ 2024-06-03 4/week @ 2024-06-10 2/week @ 2024-06-17 13/week @ 2024-06-24 10/week @ 2024-07-01 25/week @ 2024-07-08 9/week @ 2024-07-15

58 downloads per month
Used in 2 crates

MIT license

9KB
149 lines

documentation Crates.io Crates.io (recent)

envor

Get env vars to types with default.

Usage

use envor::envor::*;

fn main() {
    let config_value: usize = env_or("CONFIG_VALUE", 100);

    let flag: bool = env_or("SETTING", false);

    let config_string = env_string_or("CONFIG_STRING", "default string");

    let flag_env_true = env_true("FLAG_ONLY_TRUE_WHEN_DEFINED_AND_ITS_LOWER_CASE_IS_EQUAL_TO_TRUE");

    println!(
        "config_value = {} , setting = {} , config_string = {} , flag_env_true = {}",
        config_value, flag, config_string, flag_env_true
    );
}

Advanced

use envor::envor::*;

fn main() {
    let opt_value_ok: Option<i32> = env_or_opt("OPT_VALUE", -50);

    let opt_value_illegal: Option<i32> = env_or_opt("OPT_VALUE", "illegal default");

    println!(
        "opt_value_ok = {:?} , opt_value_illegal = {:?}",
        opt_value_ok, opt_value_illegal
    );
}

Logging

export RUST_LOG=info
# or
export RUST_LOG=debug

Dependencies

~34KB