#environment #variables

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

#4 in #variables

Download history 68/week @ 2021-08-07 72/week @ 2021-08-14 22/week @ 2021-08-21 22/week @ 2021-09-04 40/week @ 2021-09-11 16/week @ 2021-09-18 71/week @ 2021-09-25 32/week @ 2021-10-02 216/week @ 2021-10-09 102/week @ 2021-10-16 185/week @ 2021-10-23 50/week @ 2021-10-30 82/week @ 2021-11-06 58/week @ 2021-11-13 53/week @ 2021-11-20

158 downloads per month
Used in kube-event-exporter

MIT/Apache

9KB
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

~80KB

b`