3个版本 (稳定版)
1.0.1 | 2021年1月17日 |
---|---|
0.1.0 | 2021年1月17日 |
在Rust模式中排名第1684
每月下载量601次
用于 2 crates
10KB
170 行
env-var
提供更容易访问Rust中环境变量的宏。
许可证
env-var在Apache License,版本2.0和MIT许可证下双许可。
用法
将以下内容放入您的Cargo.toml
[dependencies]
env-var = "1"
log = "0.4"
示例
#[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");
}
依赖项
~87KB