serde-env-field
This crate provides the EnvField<T>
type capable of deserializing the T
type
from a string with environment variables expanded.
During deserialization, the EnvField
will try to deserialize the data as a string and expand all
the environment variables. After the expansion, the resulting string will be used
to construct the T
value.
By default, the EnvField
will construct the T
value using the FromStr
trait.
However, it is possible to make it use the Deserialize
trait using the UseDeserialize marker.
If the supplied data was not a string, the EnvField
will attempt to deserialize the T
type directly from the data.
The EnvField
works nicely with Option
, Vec
, and #[serde(default)]
.
Also, the crate provides the env_field_wrap attribute that wraps all the fields of a struct or an enum with the EnvField
type.
The attribute also honors the optional and vector fields.
EnvField
Example
;
let de: Example = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
set_var
env_field_wrap
Example
;
let de: Example = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
set_var
See the documentation of the EnvField and the env_field_wrap for details.