Expand description
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"),
});
Modules§
- encoding
- Module that defines
Encoding
whith allows for customization of the encoding format, and theDEFAULT
encoding configuration.
Structs§
Traits§
- Parser
- Trait governing how JSON is parsed depending on the kind of buffer provided.
Functions§
- decode
- Decode the given type
T
from the givenParser
using theDEFAULT
configuration. - encode
- Encode the given value to the given
Writer
using theDEFAULT
configuration. - from_
slice - Decode the given type
T
from the given slice using theDEFAULT
configuration. - from_
str - Decode the given type
T
from the given string using theDEFAULT
configuration. - to_
fixed_ bytes - Encode the given value to a fixed-size bytes using the
DEFAULT
configuration. - to_
string alloc
- Encode the given value to a
String
using theDEFAULT
configuration. - to_vec
alloc
- Encode the given value to a
Vec
using theDEFAULT
configuration. - to_
writer std
- Encode the given value to the given Write using the
DEFAULT
configuration.
Type Aliases§
- Result
- Convenient result alias for use with
musli_json
.