pub struct Serializer<W, P> { /* private fields */ }
Expand description
serde
serializer for binary data format which may preserve lexicographic ordering of values
The data format is customizable: you can choose lexicographic ordering for encoding
of primitive types, endianness, encoding of lengths and enum discriminants; please see
SerializerParams
trait. This crate provides params::AscendingOrder
, which is a default
parameter set for Serializer
which has the property to preserve lexicographic ordering
of serialized values. To obtain the descending lexicographic ordering, the resulting byte buffer
should be bitwise inverted, e.g. with primitives::invert_buffer())
.
Serializer requires access to a double-ended data buffer, which should implement
WriteBytes
and TailWriteBytes
traits. This crate provides a DeWriteBuffer
type, which
is a wrapper around a user-provided mutable slice to be used as a write buffer.
Serializer does not allocate anything: double-ended buffer should be big enough to contain
serialized data. To know required buffer size in advance, please use calc_size
with the same
SerializerParams
. Size calculation is cheap, for fixed-size structures it folds into
compile-time constant.
Implementations§
Source§impl<W, P> Serializer<W, P>where
W: TailWriteBytes,
P: SerializerParams,
impl<W, P> Serializer<W, P>where
W: TailWriteBytes,
P: SerializerParams,
pub fn new(writer: W, params: P) -> Self
pub fn into_writer(self) -> W
Trait Implementations§
Source§impl<W> FormatVersion<AscendingOrder> for Serializer<W, AscendingOrder>
impl<W> FormatVersion<AscendingOrder> for Serializer<W, AscendingOrder>
Source§impl<W> FormatVersion<NativeBinary> for Serializer<W, NativeBinary>
impl<W> FormatVersion<NativeBinary> for Serializer<W, NativeBinary>
Source§impl<W> FormatVersion<PortableBinary> for Serializer<W, PortableBinary>
impl<W> FormatVersion<PortableBinary> for Serializer<W, PortableBinary>
Source§impl<'a, W, P> Serializer for &'a mut Serializer<W, P>where
W: TailWriteBytes,
P: SerializerParams,
impl<'a, W, P> Serializer for &'a mut Serializer<W, P>where
W: TailWriteBytes,
P: SerializerParams,
Source§type Ok = ()
type Ok = ()
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 = SerializeCompoundSeq<'a, W, P>
type SerializeSeq = SerializeCompoundSeq<'a, W, P>
serialize_seq
for serializing the content of the
sequence.Source§type SerializeTuple = SerializeCompound<'a, W, P>
type SerializeTuple = SerializeCompound<'a, W, P>
serialize_tuple
for serializing the content of
the tuple.Source§type SerializeTupleStruct = SerializeCompound<'a, W, P>
type SerializeTupleStruct = SerializeCompound<'a, W, P>
serialize_tuple_struct
for serializing the
content of the tuple struct.Source§type SerializeTupleVariant = SerializeCompound<'a, W, P>
type SerializeTupleVariant = SerializeCompound<'a, W, P>
serialize_tuple_variant
for serializing the
content of the tuple variant.Source§type SerializeMap = SerializeCompoundSeq<'a, W, P>
type SerializeMap = SerializeCompoundSeq<'a, W, P>
serialize_map
for serializing the content of the
map.Source§type SerializeStruct = SerializeCompound<'a, W, P>
type SerializeStruct = SerializeCompound<'a, W, P>
serialize_struct
for serializing the content of
the struct.Source§type SerializeStructVariant = SerializeCompound<'a, W, P>
type SerializeStructVariant = SerializeCompound<'a, W, P>
serialize_struct_variant
for serializing the
content of the struct variant.Source§fn serialize_some<T>(self, value: &T) -> Result
fn serialize_some<T>(self, value: &T) -> Result
Source§fn serialize_unit(self) -> Result
fn serialize_unit(self) -> Result
()
value. Read moreSource§fn serialize_unit_struct(self, _name: &'static str) -> Result
fn serialize_unit_struct(self, _name: &'static str) -> Result
Source§fn serialize_unit_variant(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
) -> Result
fn serialize_unit_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, ) -> Result
Source§fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result
struct Millimeters(u8)
. Read moreSource§fn serialize_newtype_variant<T>(
self,
_name: &'static str,
variant_index: u32,
_variant: &'static str,
value: &T,
) -> Result
fn serialize_newtype_variant<T>( self, _name: &'static str, variant_index: u32, _variant: &'static str, value: &T, ) -> Result
Source§fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple>
fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple>
serialize_element
,
then a call to end
. Read moreSource§fn serialize_tuple_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<Self::SerializeTupleStruct>
fn serialize_tuple_struct( self, _name: &'static str, _len: usize, ) -> Result<Self::SerializeTupleStruct>
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<Self::SerializeTupleVariant>
fn serialize_tuple_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<Self::SerializeTupleVariant>
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_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<Self::SerializeStruct>
fn serialize_struct( self, _name: &'static str, _len: usize, ) -> Result<Self::SerializeStruct>
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<Self::SerializeStructVariant>
fn serialize_struct_variant( self, _name: &'static str, variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<Self::SerializeStructVariant>
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_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq>
serialize_element
, then a call to
end
. Read moreSource§fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap>
serialize_key
and serialize_value
, then a call to end
. 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>
Source§fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
Source§fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
Display
. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Serialize
implementations should serialize in
human-readable form. Read more