env-var

Crates.ioenv-var
lib.rsenv-var
version1.0.1
sourcesrc
created_at2021-01-17 16:40:29.140437
updated_at2021-01-17 19:47:46.286314
descriptionMacros providing easier access to environment variables in rust.
homepage
repositoryhttps://github.com/apimeister/env-var-macro-rs/
max_upload_size
id343186
size32,880
Jens Walter (JensWalter)

documentation

README

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");

}
Commit count: 6

cargo fmt