simd-json-derive

Crates.iosimd-json-derive
lib.rssimd-json-derive
version0.13.0
sourcesrc
created_at2020-06-17 07:33:39.622572
updated_at2023-10-26 11:23:12.118967
descriptionderives for simd-json
homepagehttps://docs.rs/simd-json-derive
repositoryhttps://github.com/simd-lite/simd-json-derive/
max_upload_size
id254847
size115,365
SIMD-lite bot (simd-lite-bot)

documentation

https://docs.rs/simd-json-derive

README

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

Attributres 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
Commit count: 148

cargo fmt