pub struct Serializer<W, O>where
O: Options,{ /* private fields */ }
Expand description
An Serializer that encodes values directly into a Writer.
The specified byte-order will impact the endianness that is used during the encoding.
This struct should not be used often.
For most cases, prefer the encode_into
function.
Implementations§
Source§impl<W, O> Serializer<W, O>
impl<W, O> Serializer<W, O>
Sourcepub fn new(w: W, options: O) -> Serializer<W, O>
pub fn new(w: W, options: O) -> Serializer<W, O>
Creates a new Serializer with the given Write
r.
Trait Implementations§
Source§impl<'a, W, O> Serializer for &'a mut Serializer<W, O>
impl<'a, W, O> Serializer for &'a mut Serializer<W, O>
Source§type Ok = ()
type Ok = ()
The output type produced by this
Serializer
during successful
serialization. Most serializers that produce text or binary output
should set Ok = ()
and serialize into an io::Write
or buffer
contained within the Serializer
instance. Serializers that build
in-memory data structures may be simplified by using Ok
to propagate
the data structure around.Source§type SerializeSeq = Compound<'a, W, O>
type SerializeSeq = Compound<'a, W, O>
Type returned from
serialize_seq
for serializing the content of the
sequence.Source§type SerializeTuple = Compound<'a, W, O>
type SerializeTuple = Compound<'a, W, O>
Type returned from
serialize_tuple
for serializing the content of
the tuple.Source§type SerializeTupleStruct = Compound<'a, W, O>
type SerializeTupleStruct = Compound<'a, W, O>
Type returned from
serialize_tuple_struct
for serializing the
content of the tuple struct.Source§type SerializeTupleVariant = Compound<'a, W, O>
type SerializeTupleVariant = Compound<'a, W, O>
Type returned from
serialize_tuple_variant
for serializing the
content of the tuple variant.Source§type SerializeMap = Compound<'a, W, O>
type SerializeMap = Compound<'a, W, O>
Type returned from
serialize_map
for serializing the content of the
map.Source§type SerializeStruct = Compound<'a, W, O>
type SerializeStruct = Compound<'a, W, O>
Type returned from
serialize_struct
for serializing the content of
the struct.Source§type SerializeStructVariant = Compound<'a, W, O>
type SerializeStructVariant = Compound<'a, W, O>
Type returned from
serialize_struct_variant
for serializing the
content of the struct variant.Source§fn serialize_bool(self, v: bool) -> Result<(), Box<ErrorKind>>
fn serialize_bool(self, v: bool) -> Result<(), Box<ErrorKind>>
Serialize a
bool
value. Read moreSource§fn serialize_i16(self, v: i16) -> Result<(), Box<ErrorKind>>
fn serialize_i16(self, v: i16) -> Result<(), Box<ErrorKind>>
Serialize an
i16
value. Read moreSource§fn serialize_i32(self, v: i32) -> Result<(), Box<ErrorKind>>
fn serialize_i32(self, v: i32) -> Result<(), Box<ErrorKind>>
Serialize an
i32
value. Read moreSource§fn serialize_i64(self, v: i64) -> Result<(), Box<ErrorKind>>
fn serialize_i64(self, v: i64) -> Result<(), Box<ErrorKind>>
Serialize an
i64
value. Read moreSource§fn serialize_u128(self, v: u128) -> Result<(), Box<ErrorKind>>
fn serialize_u128(self, v: u128) -> Result<(), Box<ErrorKind>>
Serialize a
u128
value. Read moreSource§fn serialize_i128(self, v: i128) -> Result<(), Box<ErrorKind>>
fn serialize_i128(self, v: i128) -> Result<(), Box<ErrorKind>>
Serialize an
i128
value. Read moreSource§fn serialize_f32(self, v: f32) -> Result<(), Box<ErrorKind>>
fn serialize_f32(self, v: f32) -> Result<(), Box<ErrorKind>>
Serialize an
f32
value. Read moreSource§fn serialize_f64(self, v: f64) -> Result<(), Box<ErrorKind>>
fn serialize_f64(self, v: f64) -> Result<(), Box<ErrorKind>>
Serialize an
f64
value. Read moreSource§fn serialize_char(self, c: char) -> Result<(), Box<ErrorKind>>
fn serialize_char(self, c: char) -> Result<(), Box<ErrorKind>>
Serialize a character. Read more
Source§fn serialize_bytes(self, v: &[u8]) -> Result<(), Box<ErrorKind>>
fn serialize_bytes(self, v: &[u8]) -> Result<(), Box<ErrorKind>>
Serialize a chunk of raw byte data. Read more
Source§fn serialize_seq(
self,
len: Option<usize>,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeSeq, Box<ErrorKind>>
fn serialize_seq( self, len: Option<usize>, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeSeq, Box<ErrorKind>>
Begin to serialize a variably sized sequence. This call must be
followed by zero or more calls to
serialize_element
, then a call to
end
. Read moreSource§fn serialize_tuple(
self,
_len: usize,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTuple, Box<ErrorKind>>
fn serialize_tuple( self, _len: usize, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTuple, Box<ErrorKind>>
Begin to serialize a statically sized sequence whose length will be
known at deserialization time without looking at the serialized data.
This call must be followed by zero or more calls to
serialize_element
,
then a call to end
. Read moreSource§fn serialize_tuple_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTupleStruct, Box<ErrorKind>>
fn serialize_tuple_struct( self, _name: &'static str, _len: usize, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTupleStruct, Box<ErrorKind>>
Begin to serialize a tuple struct like
struct Rgb(u8, u8, u8)
. This
call must be followed by zero or more calls to serialize_field
, then a
call to end
. Read moreSource§fn serialize_tuple_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTupleVariant, Box<ErrorKind>>
fn serialize_tuple_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeTupleVariant, Box<ErrorKind>>
Begin to serialize a tuple variant like
E::T
in enum E { T(u8, u8) }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read moreSource§fn serialize_map(
self,
len: Option<usize>,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeMap, Box<ErrorKind>>
fn serialize_map( self, len: Option<usize>, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeMap, Box<ErrorKind>>
Begin to serialize a map. This call must be followed by zero or more
calls to
serialize_key
and serialize_value
, then a call to end
. Read moreSource§fn serialize_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeStruct, Box<ErrorKind>>
fn serialize_struct( self, _name: &'static str, _len: usize, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeStruct, Box<ErrorKind>>
Begin to serialize a struct like
struct Rgb { r: u8, g: u8, b: u8 }
.
This call must be followed by zero or more calls to serialize_field
,
then a call to end
. Read moreSource§fn serialize_struct_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeStructVariant, Box<ErrorKind>>
fn serialize_struct_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<<&'a mut Serializer<W, O> as Serializer>::SerializeStructVariant, Box<ErrorKind>>
Begin to serialize a struct variant like
E::S
in enum E { S { r: u8, g: u8, b: u8 } }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read moreSource§fn serialize_newtype_struct<T>(
self,
_name: &'static str,
value: &T,
) -> Result<(), Box<ErrorKind>>
fn serialize_newtype_struct<T>( self, _name: &'static str, value: &T, ) -> Result<(), Box<ErrorKind>>
Serialize a newtype struct like
struct Millimeters(u8)
. Read moreSource§fn serialize_newtype_variant<T>(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
value: &T,
) -> Result<(), Box<ErrorKind>>
fn serialize_newtype_variant<T>( self, _name: &'static str, variant_index: u32, _variant: &'static str, value: &T, ) -> Result<(), Box<ErrorKind>>
Source§fn serialize_unit_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
) -> Result<(), Box<ErrorKind>>
fn serialize_unit_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, ) -> Result<(), Box<ErrorKind>>
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Determine whether
Serialize
implementations should serialize in
human-readable form. Read moreSource§fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
Collect an iterator as a sequence. Read more
Auto Trait Implementations§
impl<W, O> Freeze for Serializer<W, O>
impl<W, O> RefUnwindSafe for Serializer<W, O>where
W: RefUnwindSafe,
O: RefUnwindSafe,
impl<W, O> Send for Serializer<W, O>
impl<W, O> Sync for Serializer<W, O>
impl<W, O> Unpin for Serializer<W, O>
impl<W, O> UnwindSafe for Serializer<W, O>where
W: UnwindSafe,
O: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more