#env-var #variables #environment #access #macro #optional #found

env-var

Macros providing easier access to environment variables in rust

3 releases (stable)

1.0.1 Jan 17, 2021
0.1.0 Jan 17, 2021

#1684 in Rust patterns

Download history 104/week @ 2024-03-15 334/week @ 2024-03-22 179/week @ 2024-03-29 125/week @ 2024-04-05 353/week @ 2024-04-12 127/week @ 2024-04-19 282/week @ 2024-04-26 203/week @ 2024-05-03 135/week @ 2024-05-10 51/week @ 2024-05-17 149/week @ 2024-05-24 212/week @ 2024-05-31 58/week @ 2024-06-07 16/week @ 2024-06-14 243/week @ 2024-06-21 253/week @ 2024-06-28

601 downloads per month
Used in 2 crates

MIT/Apache

10KB
170 lines

env-var

Latest Version

Macros providing easier access to environment variables in rust.

License

env-var is dual-licensed under Apache License, Version 2.0 and MIT license.

Usage

Put this in your Cargo.toml:

[dependencies]
env-var = "1"
log = "0.4"

Examples

#[macro_use]
extern crate env_var;

fn main() {
  // retrieving a optional value
  // var1 either contains the value or an empty string
  let var1 = env_var!(optional "TEST_OPT_1");

  // retrieving a optional value with default
  // var1 either contains the value or "default1"
  let var1 = env_var!(optional "TEST_OPT_1", default: "default1");

  // retrieving a optional value with default
  // if not found, the message will be logged as info message
  // var1 either contains the value or "default1"
  let var1 = env_var!(optional "TEST_OPT_1", default: "default1", msg: "using default");

  // retrieving a required value
  // var1 either contains the value or the programm panics
  let var1 = env_var!(required "TEST_OPT_1");

  // retrieving a required value with default
  // var1 either contains the value or "default1"
  let var1 = env_var!(required "TEST_OPT_1", default: "default1");

  // retrieving a required value with default
  // if not found, the message will be logged as warn message
  // var1 either contains the value or "default1"
  let var1 = env_var!(required "TEST_OPT_1", default: "default1", msg: "using default");

}

Dependencies

~87KB