structenv

Crates.iostructenv
lib.rsstructenv
version0.0.1
sourcesrc
created_at2018-09-18 07:10:03.883863
updated_at2018-09-18 07:10:03.883863
descriptioninitialize structs from environment variable
homepage
repositoryhttps://github.com/KeenS/structenv
max_upload_size
id85321
size1,537
Îșeen (KeenS)

documentation

https://docs.rs/structenv

README

StructEnv

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) }
Commit count: 1

cargo fmt