2 unstable releases

0.2.0 Jul 8, 2024
0.1.0 Jan 14, 2022

#149 in Procedural macros

Download history 7556/week @ 2024-03-30 8413/week @ 2024-04-06 8236/week @ 2024-04-13 10013/week @ 2024-04-20 8281/week @ 2024-04-27 9686/week @ 2024-05-04 10593/week @ 2024-05-11 7246/week @ 2024-05-18 6892/week @ 2024-05-25 5948/week @ 2024-06-01 6318/week @ 2024-06-08 7062/week @ 2024-06-15 7540/week @ 2024-06-22 5578/week @ 2024-06-29 9501/week @ 2024-07-06 7508/week @ 2024-07-13

30,788 downloads per month
Used in 6 crates (5 directly)

MIT license

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–1.1MB
~25K SLoC