#derive #cli #variables #initialization #structs #env #environment

macro structenv_derive

initialize structs from environment variable

1 unstable release

Uses old Rust 2015

0.0.1 Sep 18, 2018

#146 in #initialization

Apache-2.0/MIT

7KB
134 lines

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) }

Dependencies

~2MB
~46K SLoC