Struct serde_content::Serializer
source · pub struct Serializer<'a> { /* private fields */ }
Expand description
A structure for serialising Rust values into crate::Value.
Implementations§
source§impl<'a> Serializer<'a>
impl<'a> Serializer<'a>
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a serializer.
The serializer created doesn’t serialize in human-readable form. To serialize in human-readable form, call Serializer::human_readable on the resulting serializer.
Examples found in repository?
examples/point.rs (line 16)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fn main() -> serde_content::Result<()> {
let point = Point { x: 1, y: 2 };
// Convert the Point to the Value type.
let serialized = Serializer::new().serialize(&point)?;
// Pretty print the serialised Value.
dbg!(&serialized);
// Convert the Value back to a Point.
let deserialized: Point = Deserializer::new(serialized).deserialize()?;
// Pretty print the deserialised Point.
dbg!(deserialized);
Ok(())
}
sourcepub const fn human_readable(self) -> Self
pub const fn human_readable(self) -> Self
Make Serialize
implementations serialize in human-readable form.
sourcepub fn serialize<T>(self, value: T) -> Result<Value<'a>, Error>where
T: Serialize,
pub fn serialize<T>(self, value: T) -> Result<Value<'a>, Error>where
T: Serialize,
Convert a T
into Value
which is an enum that can represent any valid Rust data.
Examples found in repository?
examples/point.rs (line 16)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
fn main() -> serde_content::Result<()> {
let point = Point { x: 1, y: 2 };
// Convert the Point to the Value type.
let serialized = Serializer::new().serialize(&point)?;
// Pretty print the serialised Value.
dbg!(&serialized);
// Convert the Value back to a Point.
let deserialized: Point = Deserializer::new(serialized).deserialize()?;
// Pretty print the deserialised Point.
dbg!(deserialized);
Ok(())
}
Trait Implementations§
source§impl<'a> Clone for Serializer<'a>
impl<'a> Clone for Serializer<'a>
source§fn clone(&self) -> Serializer<'a>
fn clone(&self) -> Serializer<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for Serializer<'a>
impl<'a> Debug for Serializer<'a>
source§impl<'a> Default for Serializer<'a>
impl<'a> Default for Serializer<'a>
source§fn default() -> Serializer<'a>
fn default() -> Serializer<'a>
Returns the “default value” for a type. Read more
source§impl<'a> PartialEq for Serializer<'a>
impl<'a> PartialEq for Serializer<'a>
source§impl<'a> PartialOrd for Serializer<'a>
impl<'a> PartialOrd for Serializer<'a>
source§impl<'a> Serializer for Serializer<'a>
impl<'a> Serializer for Serializer<'a>
§type Ok = Value<'a>
type Ok = Value<'a>
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.§type SerializeSeq = Seq<'a>
type SerializeSeq = Seq<'a>
Type returned from
serialize_seq
for serializing the content of the
sequence.§type SerializeTuple = Tuple<'a>
type SerializeTuple = Tuple<'a>
Type returned from
serialize_tuple
for serializing the content of
the tuple.§type SerializeTupleStruct = Struct<'a>
type SerializeTupleStruct = Struct<'a>
Type returned from
serialize_tuple_struct
for serializing the
content of the tuple struct.§type SerializeTupleVariant = Enum<'a>
type SerializeTupleVariant = Enum<'a>
Type returned from
serialize_tuple_variant
for serializing the
content of the tuple variant.§type SerializeMap = Map<'a>
type SerializeMap = Map<'a>
Type returned from
serialize_map
for serializing the content of the
map.§type SerializeStruct = Struct<'a>
type SerializeStruct = Struct<'a>
Type returned from
serialize_struct
for serializing the content of
the struct.§type SerializeStructVariant = Enum<'a>
type SerializeStructVariant = Enum<'a>
Type returned from
serialize_struct_variant
for serializing the
content of the struct variant.source§fn serialize_bool(self, value: bool) -> Result<Self::Ok, Error>
fn serialize_bool(self, value: bool) -> Result<Self::Ok, Error>
Serialize a
bool
value. Read moresource§fn serialize_i16(self, value: i16) -> Result<Self::Ok, Error>
fn serialize_i16(self, value: i16) -> Result<Self::Ok, Error>
Serialize an
i16
value. Read moresource§fn serialize_i32(self, value: i32) -> Result<Self::Ok, Error>
fn serialize_i32(self, value: i32) -> Result<Self::Ok, Error>
Serialize an
i32
value. Read moresource§fn serialize_i64(self, value: i64) -> Result<Self::Ok, Error>
fn serialize_i64(self, value: i64) -> Result<Self::Ok, Error>
Serialize an
i64
value. Read moresource§fn serialize_i128(self, value: i128) -> Result<Self::Ok, Error>
fn serialize_i128(self, value: i128) -> Result<Self::Ok, Error>
Serialize an
i128
value. Read moresource§fn serialize_u16(self, value: u16) -> Result<Self::Ok, Error>
fn serialize_u16(self, value: u16) -> Result<Self::Ok, Error>
Serialize a
u16
value. Read moresource§fn serialize_u32(self, value: u32) -> Result<Self::Ok, Error>
fn serialize_u32(self, value: u32) -> Result<Self::Ok, Error>
Serialize a
u32
value. Read moresource§fn serialize_u64(self, value: u64) -> Result<Self::Ok, Error>
fn serialize_u64(self, value: u64) -> Result<Self::Ok, Error>
Serialize a
u64
value. Read moresource§fn serialize_u128(self, value: u128) -> Result<Self::Ok, Error>
fn serialize_u128(self, value: u128) -> Result<Self::Ok, Error>
Serialize a
u128
value. Read moresource§fn serialize_f32(self, value: f32) -> Result<Self::Ok, Error>
fn serialize_f32(self, value: f32) -> Result<Self::Ok, Error>
Serialize an
f32
value. Read moresource§fn serialize_f64(self, value: f64) -> Result<Self::Ok, Error>
fn serialize_f64(self, value: f64) -> Result<Self::Ok, Error>
Serialize an
f64
value. Read moresource§fn serialize_char(self, value: char) -> Result<Self::Ok, Error>
fn serialize_char(self, value: char) -> Result<Self::Ok, Error>
Serialize a character. Read more
source§fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Error>
fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Error>
Serialize a chunk of raw byte data. Read more
source§fn serialize_unit_variant(
self,
name: &'static str,
variant_index: u32,
variant: &'static str,
) -> Result<Self::Ok, Error>
fn serialize_unit_variant( self, name: &'static str, variant_index: u32, variant: &'static str, ) -> Result<Self::Ok, Error>
source§fn serialize_newtype_struct<T>(
self,
name: &'static str,
value: &T,
) -> Result<Self::Ok, Error>
fn serialize_newtype_struct<T>( self, name: &'static str, value: &T, ) -> Result<Self::Ok, Error>
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<Self::Ok, Error>
fn serialize_newtype_variant<T>( self, name: &'static str, variant_index: u32, variant: &'static str, value: &T, ) -> Result<Self::Ok, Error>
source§fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Error>
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Error>
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<Self::SerializeTuple, Error>
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Error>
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<Self::SerializeTupleStruct, Error>
fn serialize_tuple_struct( self, name: &'static str, len: usize, ) -> Result<Self::SerializeTupleStruct, Error>
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<Self::SerializeTupleVariant, Error>
fn serialize_tuple_variant( self, name: &'static str, variant_index: u32, variant: &'static str, len: usize, ) -> Result<Self::SerializeTupleVariant, Error>
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<Self::SerializeMap, Error>
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Error>
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<Self::SerializeStruct, Error>
fn serialize_struct( self, name: &'static str, len: usize, ) -> Result<Self::SerializeStruct, Error>
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<Self::SerializeStructVariant, Error>
fn serialize_struct_variant( self, name: &'static str, variant_index: u32, variant: &'static str, len: usize, ) -> Result<Self::SerializeStructVariant, Error>
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 collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
fn collect_str<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
Serialize a string produced by an implementation of
Display
. Read moresource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Determine whether
Serialize
implementations should serialize in
human-readable form. Read moreimpl<'a> Copy for Serializer<'a>
impl<'a> StructuralPartialEq for Serializer<'a>
Auto Trait Implementations§
impl<'a> Freeze for Serializer<'a>
impl<'a> RefUnwindSafe for Serializer<'a>
impl<'a> Send for Serializer<'a>
impl<'a> Sync for Serializer<'a>
impl<'a> Unpin for Serializer<'a>
impl<'a> UnwindSafe for Serializer<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)