28 releases (14 breaking)

new 0.16.0 Apr 1, 2025
0.15.0 Oct 24, 2024
0.14.0 Sep 22, 2024
0.13.0 Oct 26, 2023
0.1.1 Jun 17, 2020

#1361 in Procedural macros

Download history 179/week @ 2024-12-09 92/week @ 2024-12-16 25/week @ 2024-12-23 76/week @ 2024-12-30 119/week @ 2025-01-06 26/week @ 2025-01-13 59/week @ 2025-01-20 34/week @ 2025-01-27 181/week @ 2025-02-03 273/week @ 2025-02-10 203/week @ 2025-02-17 191/week @ 2025-02-24 159/week @ 2025-03-03 183/week @ 2025-03-10 464/week @ 2025-03-17 98/week @ 2025-03-24

910 downloads per month
Used in 9 crates (via simd-json-derive)

Apache-2.0/MIT

35KB
916 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

~2.3–3.5MB
~66K SLoC