pub trait JsonSerialize {
// Required method
fn json_serialize(&self, s: &mut JsonSerializer);
// Provided methods
fn to_json_bytes(&self) -> Vec<u8> ⓘ { ... }
fn to_json_string(&self) -> String { ... }
}Expand description
Implemented by anything that can be serialized to JSON.
Default implementations are provided for primitive types, strings, arrays, HashMap, Option, and slices of tuples (for when you don’t need the “hash” part of the HashMap).
u64 and i64 numbers, even those bigger than 2**53, are written as numbers, not strings,
which might trip up other JSON parsers. If that’s a concern, consider writing numbers
as strings yourself, or sticking to u32.
Empty maps and vectors are written as {} and [], respectively, not omitted.
None Options are omitted, not written as null. There is no way to specify a
struct field that serializes to null at the moment (a custom implementation could
use Value::Null internally).
Required Methods§
sourcefn json_serialize(&self, s: &mut JsonSerializer)
fn json_serialize(&self, s: &mut JsonSerializer)
Write self to a JsonSerializer.
Provided Methods§
sourcefn to_json_bytes(&self) -> Vec<u8> ⓘ
fn to_json_bytes(&self) -> Vec<u8> ⓘ
Allocate a new Vec<u8> and serialize self to it.
sourcefn to_json_string(&self) -> String
fn to_json_string(&self) -> String
Serialize self to a String.