Struct serde_json::ser::Serializer
[−]
[src]
pub struct Serializer<W, F = CompactFormatter> { /* fields omitted */ }
A structure for serializing Rust values into JSON.
Methods
impl<W> Serializer<W> where W: Write
[src]
fn new(writer: W) -> Self
Creates a new JSON serializer.
impl<'a, W> Serializer<W, PrettyFormatter<'a>> where W: Write
[src]
fn pretty(writer: W) -> Self
Creates a new JSON pretty print serializer.
impl<W, F> Serializer<W, F> where W: Write, F: Formatter
[src]
fn with_formatter(writer: W, formatter: F) -> Self
Creates a new JSON visitor whose output will be written to the writer specified.
fn into_inner(self) -> W
Unwrap the Writer
from the Serializer
.
Trait Implementations
impl<'a, W, F> Serializer for &'a mut Serializer<W, F> where W: Write,
F: Formatter
[src]
F: Formatter
type Ok = ()
Trickery to enforce correct use of the Serialize
trait. Every Serializer
should set Ok = ()
. Read more
type Error = Error
The error type when some error occurs during serialization.
type SerializeSeq = Compound<'a, W, F>
Type returned from serialize_seq
and serialize_seq_fixed_size
for serializing the content of the sequence. Read more
type SerializeTuple = Compound<'a, W, F>
Type returned from serialize_tuple
for serializing the content of the tuple. Read more
type SerializeTupleStruct = Compound<'a, W, F>
Type returned from serialize_tuple_struct
for serializing the content of the tuple struct. Read more
type SerializeTupleVariant = Compound<'a, W, F>
Type returned from serialize_tuple_variant
for serializing the content of the tuple variant. Read more
type SerializeMap = Compound<'a, W, F>
Type returned from serialize_map
for serializing the content of the map. Read more
type SerializeStruct = Compound<'a, W, F>
Type returned from serialize_struct
for serializing the content of the struct. Read more
type SerializeStructVariant = Compound<'a, W, F>
Type returned from serialize_struct_variant
for serializing the content of the struct variant. Read more
fn serialize_bool(self, value: bool) -> Result<()>
Serializes a bool
value.
fn serialize_isize(self, value: isize) -> Result<()>
Serializes an isize
value. If the format does not differentiate between isize
and i64
, a reasonable implementation would be to cast the value to i64
and forward to serialize_i64
. Read more
fn serialize_i8(self, value: i8) -> Result<()>
Serializes an i8
value. If the format does not differentiate between i8
and i64
, a reasonable implementation would be to cast the value to i64
and forward to serialize_i64
. Read more
fn serialize_i16(self, value: i16) -> Result<()>
Serializes an i16
value. If the format does not differentiate between i16
and i64
, a reasonable implementation would be to cast the value to i64
and forward to serialize_i64
. Read more
fn serialize_i32(self, value: i32) -> Result<()>
Serializes an i32
value. If the format does not differentiate between i32
and i64
, a reasonable implementation would be to cast the value to i64
and forward to serialize_i64
. Read more
fn serialize_i64(self, value: i64) -> Result<()>
Serializes an i64
value.
fn serialize_usize(self, value: usize) -> Result<()>
Serializes a usize
value. If the format does not differentiate between usize
and u64
, a reasonable implementation would be to cast the value to u64
and forward to serialize_u64
. Read more
fn serialize_u8(self, value: u8) -> Result<()>
Serializes a u8
value. If the format does not differentiate between u8
and u64
, a reasonable implementation would be to cast the value to u64
and forward to serialize_u64
. Read more
fn serialize_u16(self, value: u16) -> Result<()>
Serializes a u16
value. If the format does not differentiate between u16
and u64
, a reasonable implementation would be to cast the value to u64
and forward to serialize_u64
. Read more
fn serialize_u32(self, value: u32) -> Result<()>
Serializes a u32
value. If the format does not differentiate between u32
and u64
, a reasonable implementation would be to cast the value to u64
and forward to serialize_u64
. Read more
fn serialize_u64(self, value: u64) -> Result<()>
Serializes a
u64` value.
fn serialize_f32(self, value: f32) -> Result<()>
Serializes an f32
value. If the format does not differentiate between f32
and f64
, a reasonable implementation would be to cast the value to f64
and forward to serialize_f64
. Read more
fn serialize_f64(self, value: f64) -> Result<()>
Serializes an f64
value.
fn serialize_char(self, value: char) -> Result<()>
Serializes a character. If the format does not support characters, it is reasonable to serialize it as a single element str
or a u32
. Read more
fn serialize_str(self, value: &str) -> Result<()>
Serializes a &str
.
fn serialize_bytes(self, value: &[u8]) -> Result<()>
Enables serializers to serialize byte slices more compactly or more efficiently than other types of slices. If no efficient implementation is available, a reasonable implementation would be to forward to serialize_seq
. If forwarded, the implementation looks usually just like this: rust let mut seq = self.serialize_seq(Some(value.len()))?; for b in value { seq.serialize_element(b)?; } seq.end()
Read more
fn serialize_unit(self) -> Result<()>
Serializes a ()
value. It's reasonable to just not serialize anything.
fn serialize_unit_struct(self, _name: &'static str) -> Result<()>
Serializes a unit struct value. A reasonable implementation would be to forward to serialize_unit
. Read more
fn serialize_unit_variant(self,
_name: &'static str,
_variant_index: usize,
variant: &'static str)
-> Result<()>
_name: &'static str,
_variant_index: usize,
variant: &'static str)
-> Result<()>
Serializes a unit variant, otherwise known as a variant with no arguments. A reasonable implementation would be to forward to serialize_unit
. Read more
fn serialize_newtype_struct<T: ?Sized>(self,
_name: &'static str,
value: &T)
-> Result<()> where T: Serialize
_name: &'static str,
value: &T)
-> Result<()> where T: Serialize
Serialize newtypes without an object wrapper.
fn serialize_newtype_variant<T: ?Sized>(self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
value: &T)
-> Result<()> where T: Serialize
_name: &'static str,
_variant_index: usize,
variant: &'static str,
value: &T)
-> Result<()> where T: Serialize
Allows a variant with a single item to be more efficiently serialized than a variant with multiple items. A reasonable implementation would be to forward to serialize_tuple_variant
. Read more
fn serialize_none(self) -> Result<()>
Serializes a None
value.
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<()> where T: Serialize
Serializes a Some(...)
value.
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>
Begins to serialize a sequence. This call must be followed by zero or more calls to serialize_seq_elt
, then a call to serialize_seq_end
. Read more
fn serialize_seq_fixed_size(self, size: usize) -> Result<Self::SerializeSeq>
Begins to serialize a sequence whose length will be known at deserialization time. This call must be followed by zero or more calls to serialize_seq_elt
, then a call to serialize_seq_end
. A reasonable implementation would be to forward to serialize_seq
. Read more
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple>
Begins to serialize a tuple. This call must be followed by zero or more calls to serialize_tuple_elt
, then a call to serialize_tuple_end
. A reasonable implementation would be to forward to serialize_seq
. Read more
fn serialize_tuple_struct(self,
_name: &'static str,
len: usize)
-> Result<Self::SerializeTupleStruct>
_name: &'static str,
len: usize)
-> Result<Self::SerializeTupleStruct>
Begins to serialize a tuple struct. This call must be followed by zero or more calls to serialize_tuple_struct_elt
, then a call to serialize_tuple_struct_end
. A reasonable implementation would be to forward to serialize_tuple
. Read more
fn serialize_tuple_variant(self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize)
-> Result<Self::SerializeTupleVariant>
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize)
-> Result<Self::SerializeTupleVariant>
Begins to serialize a tuple variant. This call must be followed by zero or more calls to serialize_tuple_variant_elt
, then a call to serialize_tuple_variant_end
. A reasonable implementation would be to forward to serialize_tuple_struct
. Read more
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>
Begins to serialize a map. This call must be followed by zero or more calls to serialize_map_key
and serialize_map_value
, then a call to serialize_map_end
. Read more
fn serialize_struct(self,
_name: &'static str,
len: usize)
-> Result<Self::SerializeStruct>
_name: &'static str,
len: usize)
-> Result<Self::SerializeStruct>
Begins to serialize a struct. This call must be followed by zero or more calls to serialize_struct_elt
, then a call to serialize_struct_end
. Read more
fn serialize_struct_variant(self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize)
-> Result<Self::SerializeStructVariant>
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize)
-> Result<Self::SerializeStructVariant>
Begins to serialize a struct variant. This call must be followed by zero or more calls to serialize_struct_variant_elt
, then a call to serialize_struct_variant_end
. Read more