Struct Serializer
pub struct Serializer;
Serializer whose output is a Value.
This is the serializer that backs [serde_json::to_value][crate::to_value].
Unlike the main serde_json serializer which goes from some serializable
value of type T to JSON text, this one goes from T to
serde_json::Value.
The to_value function is implementable as:
use serde::Serialize;
use serde_json::{Error, Value};
pub fn to_value<T>(input: T) -> Result<Value, Error>
where
T: Serialize,
{
input.serialize(serde_json::value::Serializer)
}
Trait Implementations
impl Serializer for Serializer
type Ok = Value;type Error = Error;type SerializeSeq = SerializeVec;type SerializeTuple = SerializeVec;type SerializeTupleStruct = SerializeVec;type SerializeTupleVariant = SerializeTupleVariant;type SerializeMap = SerializeMap;type SerializeStruct = SerializeMap;type SerializeStructVariant = SerializeStructVariant;fn serialize_bool(self, value: bool) -> Result<Value>fn serialize_i8(self, value: i8) -> Result<Value>fn serialize_i16(self, value: i16) -> Result<Value>fn serialize_i32(self, value: i32) -> Result<Value>fn serialize_i64(self, value: i64) -> Result<Value>fn serialize_i128(self, value: i128) -> Result<Value>fn serialize_u8(self, value: u8) -> Result<Value>fn serialize_u16(self, value: u16) -> Result<Value>fn serialize_u32(self, value: u32) -> Result<Value>fn serialize_u64(self, value: u64) -> Result<Value>fn serialize_u128(self, value: u128) -> Result<Value>fn serialize_f32(self, float: f32) -> Result<Value>fn serialize_f64(self, float: f64) -> Result<Value>fn serialize_char(self, value: char) -> Result<Value>fn serialize_str(self, value: &str) -> Result<Value>fn serialize_bytes(self, value: &[u8]) -> Result<Value>fn serialize_unit(self) -> Result<Value>fn serialize_unit_struct(self, _name: &'static str) -> Result<Value>fn serialize_unit_variant(self, _name: &'static str, _variant_index: u32, variant: &'static str) -> Result<Value>fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result<Value> where T: ?Sized + Serialize,fn serialize_newtype_variant<T>(self, _name: &'static str, _variant_index: u32, variant: &'static str, value: &T) -> Result<Value> where T: ?Sized + Serialize,fn serialize_none(self) -> Result<Value>fn serialize_some<T>(self, value: &T) -> Result<Value> where T: ?Sized + Serialize,fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple>fn serialize_tuple_struct(self, _name: &'static str, len: usize) -> Result<Self::SerializeTupleStruct>fn serialize_tuple_variant(self, _name: &'static str, _variant_index: u32, variant: &'static str, len: usize) -> Result<Self::SerializeTupleVariant>fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>fn serialize_struct(self, name: &'static str, len: usize) -> Result<Self::SerializeStruct>fn serialize_struct_variant(self, _name: &'static str, _variant_index: u32, variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant>fn collect_str<T>(self, value: &T) -> Result<Value> where T: ?Sized + Display,