musli-json

Crates.iomusli-json
lib.rsmusli-json
version0.0.117
sourcesrc
created_at2022-04-28 20:27:24.392812
updated_at2024-04-20 08:47:40.353732
descriptionJSON support for Müsli.
homepagehttps://github.com/udoprog/musli
repositoryhttps://github.com/udoprog/musli
max_upload_size
id576996
size144,349
John-John Tedro (udoprog)

documentation

https://docs.rs/musli

README

musli-json

github crates.io docs.rs build status

JSON support for Müsli suitable for network and usually browser communication.

JSON encoding is fully upgrade stable:

  • ✔ Can tolerate missing fields if they are annotated with #[musli(default)].
  • ✔ Can skip over unknown fields.
use musli::{Encode, Decode};

#[derive(Debug, PartialEq, Encode, Decode)]
struct Version1 {
    name: String,
}

#[derive(Debug, PartialEq, Encode, Decode)]
struct Version2 {
    name: String,
    #[musli(default)]
    age: Option<u32>,
}

let version2 = musli_json::to_vec(&Version2 {
    name: String::from("Aristotle"),
    age: Some(62),
})?;

let version1: Version1 = musli_json::from_slice(version2.as_slice())?;

assert_eq!(version1, Version1 {
    name: String::from("Aristotle"),
});
Commit count: 755

cargo fmt