2 unstable releases
0.2.0 | Jul 8, 2024 |
---|---|
0.1.0 | Jan 14, 2022 |
#172 in Procedural macros
42,403 downloads per month
Used in 6 crates
(5 directly)
11KB
191 lines
serde_default
This is a library for generating impls of Default
from serde attributes.
lib.rs
:
Generate a Default
impl based on field-level defaults in serde
attributes.
Usage
On a struct that derives Serialize
or Deserialize
, add DefaultFromSerde
.
#[derive(Debug, DefaultFromSerde, PartialEq, Eq)]
pub struct MyStruct {
#[serde(default = "field_1_default")]
field1: u16,
#[serde(default)]
field2: String,
}
fn field_1_default() -> u16 {
3
}
fn main() {
assert_eq!(MyStruct::default(), MyStruct { field1: 3, field2: "".into() });
}
Dependencies
~0.6–1MB
~24K SLoC