25 releases (11 breaking)

0.13.0 Oct 26, 2023
0.11.3 Oct 10, 2023
0.10.0 May 24, 2023
0.7.0 Nov 3, 2022
0.1.1 Jun 17, 2020

#1543 in Procedural macros

Download history 6/week @ 2023-12-05 47/week @ 2023-12-12 9/week @ 2023-12-19 7/week @ 2023-12-26 10/week @ 2024-01-02 23/week @ 2024-01-09 88/week @ 2024-01-16 39/week @ 2024-01-23 34/week @ 2024-01-30 372/week @ 2024-02-06 306/week @ 2024-02-13 571/week @ 2024-02-20 544/week @ 2024-02-27 462/week @ 2024-03-05 826/week @ 2024-03-12 295/week @ 2024-03-19

2,209 downloads per month
Used in 6 crates (via simd-json-derive)

Apache-2.0/MIT

35KB
918 lines

simd-json-derive

Latest version documentation License

Derives for high performance JSON serialisation and deserialisation.

Usage


#[derive(Serialize, Deserialize, Debug)]
#[simd_json(deny_unknown_fields, rename_all = "camelCase")]
struct MyStruct {
    first_field: String,
    #[simd_json(rename = "foo")]
    second_field: Option<usize>
}

fn main -> Result<(), simd_json::Error> {
    let my_struct = MyStruct {
        first_field: "i am first".to_string(),
        second_field: None
    }
    println!("Before: {my_struct:?}");
    let mut json_string = my_struct.json_string()?;
    let deserialized = MyStruct::from_str(json_string.as_mut_str())?;
    println!("After: {deserialized:?}");
}

Supported Attributes

Attributes are supported for both #[simd_json(...)] and for compatibilty also for #[serde(...)] and follow the same naming conventions as serde.

For fields:

  • rename = "new_name" - renames a field

For structs:

  • rename_all = "camelCase" - renames all (not otherwise renamed) based on the rule, camelCase is currently supported
  • deny_unknown_fields - Errors if unknown fields are encountered

Dependencies

~5.5MB
~100K SLoC