Trait serde::ser::Serializer
[−]
[src]
pub trait Serializer { type Error: Error; fn serialize_bool(&mut self, v: bool) -> Result<(), Self::Error>; fn serialize_i64(&mut self, v: i64) -> Result<(), Self::Error>; fn serialize_u64(&mut self, v: u64) -> Result<(), Self::Error>; fn serialize_f64(&mut self, v: f64) -> Result<(), Self::Error>; fn serialize_str(&mut self, value: &str) -> Result<(), Self::Error>; fn serialize_unit(&mut self) -> Result<(), Self::Error>; fn serialize_none(&mut self) -> Result<(), Self::Error>; fn serialize_some<V>(&mut self, value: V) -> Result<(), Self::Error> where V: Serialize; fn serialize_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor; fn serialize_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize; fn serialize_map<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: MapVisitor; fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize; fn serialize_isize(&mut self, v: isize) -> Result<(), Self::Error> { ... } fn serialize_i8(&mut self, v: i8) -> Result<(), Self::Error> { ... } fn serialize_i16(&mut self, v: i16) -> Result<(), Self::Error> { ... } fn serialize_i32(&mut self, v: i32) -> Result<(), Self::Error> { ... } fn serialize_usize(&mut self, v: usize) -> Result<(), Self::Error> { ... } fn serialize_u8(&mut self, v: u8) -> Result<(), Self::Error> { ... } fn serialize_u16(&mut self, v: u16) -> Result<(), Self::Error> { ... } fn serialize_u32(&mut self, v: u32) -> Result<(), Self::Error> { ... } fn serialize_f32(&mut self, v: f32) -> Result<(), Self::Error> { ... } fn serialize_char(&mut self, v: char) -> Result<(), Self::Error> { ... } fn serialize_bytes(&mut self, value: &[u8]) -> Result<(), Self::Error> { ... } fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<(), Self::Error> { ... } fn serialize_unit_variant(&mut self, _name: &'static str, _variant_index: usize, _variant: &'static str) -> Result<(), Self::Error> { ... } fn serialize_newtype_struct<T>(&mut self, name: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize { ... } fn serialize_newtype_variant<T>(&mut self, name: &'static str, variant_index: usize, variant: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize { ... } fn serialize_tuple<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor { ... } fn serialize_tuple_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { ... } fn serialize_fixed_size_array<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor { ... } fn serialize_tuple_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor { ... } fn serialize_tuple_struct_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { ... } fn serialize_tuple_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor { ... } fn serialize_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize { ... } fn serialize_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor { ... } fn serialize_struct_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize { ... } fn serialize_struct_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor { ... } fn serialize_struct_variant_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize { ... } }
A trait that describes a type that can serialize a stream of values into the underlying format.
Associated Types
Required Methods
fn serialize_bool(&mut self, v: bool) -> Result<(), Self::Error>
Serializes a bool
value.
fn serialize_i64(&mut self, v: i64) -> Result<(), Self::Error>
Serializes a i64
value.
fn serialize_u64(&mut self, v: u64) -> Result<(), Self::Error>
Serializes a
u64` value.
fn serialize_f64(&mut self, v: f64) -> Result<(), Self::Error>
Serializes a f64
value.
fn serialize_str(&mut self, value: &str) -> Result<(), Self::Error>
Serializes a &str
.
fn serialize_unit(&mut self) -> Result<(), Self::Error>
Serializes a ()
value.
fn serialize_none(&mut self) -> Result<(), Self::Error>
Serializes a None
value..serialize
fn serialize_some<V>(&mut self, value: V) -> Result<(), Self::Error> where V: Serialize
Serializes a Some(...)
value.
fn serialize_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor
Serializes a sequence.
Callees of this method need to construct a SeqVisitor
, which iterates through each item
in the sequence.
fn serialize_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize
Serializes a sequence element.
fn serialize_map<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: MapVisitor
Serializes a map.
Callees of this method need to construct a MapVisitor
, which iterates through each item
in the map.
fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize
Serializes a map element (key-value pair).
Provided Methods
fn serialize_isize(&mut self, v: isize) -> Result<(), Self::Error>
Serializes a isize
value. By default it casts the value to a i64
and
passes it to the serialize_i64
method.
fn serialize_i8(&mut self, v: i8) -> Result<(), Self::Error>
Serializes a i8
value. By default it casts the value to a i64
and
passes it to the serialize_i64
method.
fn serialize_i16(&mut self, v: i16) -> Result<(), Self::Error>
Serializes a i16
value. By default it casts the value to a i64
and
passes it to the serialize_i64
method.
fn serialize_i32(&mut self, v: i32) -> Result<(), Self::Error>
Serializes a i32
value. By default it casts the value to a i64
and
passes it to the serialize_i64
method.
fn serialize_usize(&mut self, v: usize) -> Result<(), Self::Error>
Serializes a usize
value. By default it casts the value to a u64
and
passes it to the serialize_u64
method.
fn serialize_u8(&mut self, v: u8) -> Result<(), Self::Error>
Serializes a u8
value. By default it casts the value to a u64
and passes
it to the serialize_u64
method.
fn serialize_u16(&mut self, v: u16) -> Result<(), Self::Error>
Serializes a u32
value. By default it casts the value to a u64
and passes
it to the serialize_u64
method.
fn serialize_u32(&mut self, v: u32) -> Result<(), Self::Error>
Serializes a u32
value. By default it casts the value to a u64
and passes
it to the serialize_u64
method.
fn serialize_f32(&mut self, v: f32) -> Result<(), Self::Error>
Serializes a f32
value. By default it casts the value to a f64
and passes
it to the serialize_f64
method.
fn serialize_char(&mut self, v: char) -> Result<(), Self::Error>
Serializes a character. By default it serializes it as a &str
containing a
single character.
fn serialize_bytes(&mut self, value: &[u8]) -> Result<(), Self::Error>
Enables those serialization formats that support serializing byte slices separately from generic arrays. By default it serializes as a regular array.
fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<(), Self::Error>
Serializes a unit struct value.
By default, unit structs are serialized as a ()
.
fn serialize_unit_variant(&mut self, _name: &'static str, _variant_index: usize, _variant: &'static str) -> Result<(), Self::Error>
Serializes a unit variant, otherwise known as a variant with no arguments.
By default, unit variants are serialized as a ()
.
fn serialize_newtype_struct<T>(&mut self, name: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize
Allows a tuple struct with a single element, also known as a newtyped value, to be more efficiently serialized than a tuple struct with multiple items. By default it just serializes the value as a tuple struct sequence.
fn serialize_newtype_variant<T>(&mut self, name: &'static str, variant_index: usize, variant: &'static str, value: T) -> Result<(), Self::Error> where T: Serialize
Allows a variant with a single item to be more efficiently serialized than a variant with multiple items. By default it just serializes the value as a tuple variant sequence.
fn serialize_tuple<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor
Serializes a tuple.
By default this serializes a tuple as a sequence.
fn serialize_tuple_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize
Serializes a tuple element.
By default, tuples are serialized as a sequence.
fn serialize_fixed_size_array<V>(&mut self, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor
Serializes a fixed-size array.
By default this serializes an array as a sequence.
fn serialize_tuple_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor
Serializes a tuple struct.
By default, tuple structs are serialized as a tuple.
fn serialize_tuple_struct_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize
Serializes a tuple struct element.
By default, tuple struct elements are serialized as a tuple element.
fn serialize_tuple_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: SeqVisitor
Serializes a tuple variant.
By default, tuple variants are serialized as a tuple struct.
fn serialize_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize
Serializes a tuple element.
By default, tuples are serialized as a sequence.
fn serialize_struct<V>(&mut self, _name: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor
Serializes a struct.
By default, structs are serialized as a map with the field name as the key.
fn serialize_struct_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize
Serializes an element of a struct.
By default, struct elements are serialized as a map element with the field name as the key.
fn serialize_struct_variant<V>(&mut self, _name: &'static str, _variant_index: usize, variant: &'static str, visitor: V) -> Result<(), Self::Error> where V: MapVisitor
Serializes a struct variant.
By default, struct variants are serialized as a struct.
fn serialize_struct_variant_elt<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize
Serializes an element of a struct variant.
By default, struct variant elements are serialized as a struct element.