Crates.io | structenv_derive |
lib.rs | structenv_derive |
version | 0.0.1 |
source | src |
created_at | 2018-09-18 07:10:53.154961 |
updated_at | 2018-09-18 07:10:53.154961 |
description | initialize structs from environment variable |
homepage | |
repository | https://github.com/KeenS/structenv |
max_upload_size | |
id | 85322 |
size | 6,638 |
initialize structs from envrionment variables
#[macro_use]
extern crate structenv_derive;
#[derive(StructEnv, Debug)]
struct Env {
foo: bool,
#[structenv(default_value = r#""bar".to_string()"#)]
bar: String,
host_address: IpAddr,
}
fn main() {
// `from_env` is generated
let env = Env::from_env();
println!("{:?}", env);
}
$ export FOO=false
$ export HOST_ADDRESS=127.0.0.2
$ cargo run -p structenv_example --bin simple
Env { foo: false, bar: "bar", host_address: V4(127.0.0.2) }