Crate musli_json
source ·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"),
});Re-exports
pub use self::encoding::to_writer;pub use self::encoding::decode;pub use self::encoding::encode;pub use self::encoding::from_slice;pub use self::encoding::to_fixed_bytes;pub use self::encoding::Encoding;pub use self::encoding::to_string;pub use self::encoding::to_vec;
Modules
- Trait used to govern allocations. Trait used to handle individual buffer allocations.
- A writer which buffers the writes before it outputs it into the backing storage.
- Helper types to set up a basic Müsli
Context. - A container which can store up to a fixed number of uninitialized bytes on the stack and read into and from it.
- Traits and utilities for dealing with integers.
- Parser trait and utilities used for musli-json.
- Functions for working with strings. The exported implementations change depending on if the
simdutf8feature is enabled. - Helpers for integrating musli with I/O types like std::io and std::io::Write.
- Trait for governing how a particular sink of bytes is written to.
Structs
- Error raised during json encoding.
Type Aliases
- Convenient result alias for use with
musli_json.