Crate default_from_serde
source ·Expand description
This crate provides a derive macro named SerdeDefault
which derives
Default
from serde::Deserialize
.
§Usage
use default_from_serde::SerdeDefault;
#[derive(SerdeDefault, Deserialize)]
pub struct ComplexTypewithDefault {
#[serde(default)]
pub a: i32,
#[serde(default = "default_b")]
pub b: String,
#[serde(default)]
pub c: Vec<i32>,
}
fn default_b() -> String {
"default".to_string()
}
fn main() {
let x = ComplexTypewithDefault::default();
assert_eq!(x.b, "default");
}
Structs§
Type Aliases§
Derive Macros§
- Derive
Default
fromserde::Deserialize
.