This is a helper library which is dedicated to make extracting value from environment variables easy.
How To Import
add below line to cargo.toml which is in your project
= "*"
Usage
use
Support Data Types
almost all of primitive types in rust are supported, include:
- String
- i8
- i16
- i32
- i64
- i128
- u8
- u16
- u32
- u64
- u128
- usize
- isize
- bool
- f32
- f64
- Option<T: FromEnv>
you can also implement FromEnv
for your type
Environment Variable Name
If not specified, all environment variables name is the upper-case of field name:
but you can use #[env_var]
tag to specify which environment variable is related to the field:
Default Value
You can specify default value for non-existing environment variable by #[env_default]
tag:
note that, the type of default value must be string, value will be convert to correspond type in from_env
function
Optional Type Field
When environment variable whic you expected does not exist, from_env
will panic if correspond field is not optional(i.e Option<T>
). Optional field will be None
if environment variable is not exists