Struct serde_env_field::UseDeserialize
source · pub struct UseDeserialize;
Expand description
A marker type for passing into the EnvField<T>
type as a second parameter.
The EnvField
will use the Deserialize
trait for constructing the T
type
after the environment variables expansion.
I.e., the T
will be deserialized directly from the string with all environment variables expanded.
Example
#[derive(Serialize, Deserialize)]
struct Example {
variant: EnvField<Variants, UseDeserialize>
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
enum Variants {
AUsefullVariant,
AnotherCoolVariant,
}
let de: Example = toml::from_str(r#"
variant = "a-usefull-variant"
"#).unwrap();
assert!(matches!(*de.variant, Variants::AUsefullVariant));
std::env::set_var("SELECTED_VARIANT", "another-cool-variant");
let de: Example = toml::from_str(r#"
variant = "$SELECTED_VARIANT"
"#).unwrap();
assert!(matches!(*de.variant, Variants::AnotherCoolVariant));
Auto Trait Implementations§
impl RefUnwindSafe for UseDeserialize
impl Send for UseDeserialize
impl Sync for UseDeserialize
impl Unpin for UseDeserialize
impl UnwindSafe for UseDeserialize
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more