Struct serde_hjson::ser::Serializer
source · [−]pub struct Serializer<W, F> { /* private fields */ }
Expand description
A structure for serializing Rust values into Hjson.
Implementations
sourceimpl<'a, W> Serializer<W, HjsonFormatter<'a>> where
W: Write,
impl<'a, W> Serializer<W, HjsonFormatter<'a>> where
W: Write,
sourceimpl<W, F> Serializer<W, F> where
W: Write,
F: Formatter,
impl<W, F> Serializer<W, F> where
W: Write,
F: Formatter,
sourcepub fn with_formatter(writer: W, formatter: F) -> Self
pub fn with_formatter(writer: W, formatter: F) -> Self
Creates a new Hjson visitor whose output will be written to the writer specified.
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Unwrap the Writer
from the Serializer
.
Trait Implementations
sourceimpl<W, F> Serializer for Serializer<W, F> where
W: Write,
F: Formatter,
impl<W, F> Serializer for Serializer<W, F> where
W: Write,
F: Formatter,
sourcefn serialize_newtype_struct<T>(
&mut self,
_name: &'static str,
value: T
) -> Result<()> where
T: Serialize,
fn serialize_newtype_struct<T>(
&mut self,
_name: &'static str,
value: T
) -> Result<()> where
T: Serialize,
Serialize newtypes without an object wrapper.
type SeqState = State
type SeqState = State
A state object that is initialized by serialize_seq
, passed to
serialize_seq_elt
, and consumed by serialize_seq_end
. Use ()
if no
state is required. Read more
type TupleState = State
type TupleState = State
A state object that is initialized by serialize_tuple
, passed to
serialize_tuple_elt
, and consumed by serialize_tuple_end
. Use ()
if no state is required. Read more
type TupleStructState = State
type TupleStructState = State
A state object that is initialized by serialize_tuple_struct
, passed
to serialize_tuple_struct_elt
, and consumed by
serialize_tuple_struct_end
. Use ()
if no state is required. Read more
type TupleVariantState = State
type TupleVariantState = State
A state object that is initialized by serialize_tuple_variant
, passed
to serialize_tuple_variant_elt
, and consumed by
serialize_tuple_variant_end
. Use ()
if no state is required. Read more
type MapState = State
type MapState = State
A state object that is initialized by serialize_map
, passed to
serialize_map_elt
, and consumed by serialize_map_end
. Use ()
if no
state is required. Read more
type StructState = State
type StructState = State
A state object that is initialized by serialize_struct
, passed to
serialize_struct_elt
, and consumed by serialize_struct_end
. Use ()
if no state is required. Read more
type StructVariantState = State
type StructVariantState = State
A state object that is initialized by serialize_struct_variant
, passed
to serialize_struct_variant_elt
, and consumed by
serialize_struct_variant_end
. Use ()
if no state is required. Read more
sourcefn serialize_bool(&mut self, value: bool) -> Result<()>
fn serialize_bool(&mut self, value: bool) -> Result<()>
Serializes a bool
value.
sourcefn serialize_isize(&mut self, value: isize) -> Result<()>
fn serialize_isize(&mut 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
sourcefn serialize_i8(&mut self, value: i8) -> Result<()>
fn serialize_i8(&mut 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
sourcefn serialize_i16(&mut self, value: i16) -> Result<()>
fn serialize_i16(&mut 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
sourcefn serialize_i32(&mut self, value: i32) -> Result<()>
fn serialize_i32(&mut 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
sourcefn serialize_i64(&mut self, value: i64) -> Result<()>
fn serialize_i64(&mut self, value: i64) -> Result<()>
Serializes an i64
value.
sourcefn serialize_usize(&mut self, value: usize) -> Result<()>
fn serialize_usize(&mut 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
sourcefn serialize_u8(&mut self, value: u8) -> Result<()>
fn serialize_u8(&mut 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
sourcefn serialize_u16(&mut self, value: u16) -> Result<()>
fn serialize_u16(&mut 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
sourcefn serialize_u32(&mut self, value: u32) -> Result<()>
fn serialize_u32(&mut 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
sourcefn serialize_u64(&mut self, value: u64) -> Result<()>
fn serialize_u64(&mut self, value: u64) -> Result<()>
Serializes a
u64` value.
sourcefn serialize_f32(&mut self, value: f32) -> Result<()>
fn serialize_f32(&mut 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
sourcefn serialize_f64(&mut self, value: f64) -> Result<()>
fn serialize_f64(&mut self, value: f64) -> Result<()>
Serializes an f64
value.
sourcefn serialize_char(&mut self, value: char) -> Result<()>
fn serialize_char(&mut 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
sourcefn serialize_str(&mut self, value: &str) -> Result<()>
fn serialize_str(&mut self, value: &str) -> Result<()>
Serializes a &str
.
sourcefn serialize_bytes(&mut self, value: &[u8]) -> Result<()>
fn serialize_bytes(&mut 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: Read more
sourcefn serialize_unit(&mut self) -> Result<()>
fn serialize_unit(&mut self) -> Result<()>
Serializes a ()
value. It’s reasonable to just not serialize anything.
sourcefn serialize_unit_struct(&mut self, _name: &'static str) -> Result<()>
fn serialize_unit_struct(&mut self, _name: &'static str) -> Result<()>
Serializes a unit struct value. A reasonable implementation would be to
forward to serialize_unit
. Read more
sourcefn serialize_unit_variant(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str
) -> Result<()>
fn serialize_unit_variant(
&mut self,
_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
sourcefn serialize_newtype_variant<T>(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
value: T
) -> Result<()> where
T: Serialize,
fn serialize_newtype_variant<T>(
&mut self,
_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
sourcefn serialize_none(&mut self) -> Result<()>
fn serialize_none(&mut self) -> Result<()>
Serializes a None
value.
sourcefn serialize_some<V>(&mut self, value: V) -> Result<()> where
V: Serialize,
fn serialize_some<V>(&mut self, value: V) -> Result<()> where
V: Serialize,
Serializes a Some(...)
value.
sourcefn serialize_seq(&mut self, len: Option<usize>) -> Result<State>
fn serialize_seq(&mut self, len: Option<usize>) -> Result<State>
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
sourcefn serialize_seq_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()> where
T: Serialize,
fn serialize_seq_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()> where
T: Serialize,
Serializes a sequence element. Must have previously called
serialize_seq
. Read more
sourcefn serialize_seq_end(&mut self, state: State) -> Result<()>
fn serialize_seq_end(&mut self, state: State) -> Result<()>
Finishes serializing a sequence.
sourcefn serialize_seq_fixed_size(&mut self, size: usize) -> Result<State>
fn serialize_seq_fixed_size(&mut self, size: usize) -> Result<State>
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
sourcefn serialize_tuple(&mut self, len: usize) -> Result<State>
fn serialize_tuple(&mut self, len: usize) -> Result<State>
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
sourcefn serialize_tuple_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
fn serialize_tuple_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
Serializes a tuple element. Must have previously called
serialize_tuple
. Read more
sourcefn serialize_tuple_end(&mut self, state: State) -> Result<()>
fn serialize_tuple_end(&mut self, state: State) -> Result<()>
Finishes serializing a tuple.
sourcefn serialize_tuple_struct(
&mut self,
_name: &'static str,
len: usize
) -> Result<State>
fn serialize_tuple_struct(
&mut self,
_name: &'static str,
len: usize
) -> Result<State>
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
sourcefn serialize_tuple_struct_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
fn serialize_tuple_struct_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
Serializes a tuple struct element. Must have previously called
serialize_tuple_struct
. Read more
sourcefn serialize_tuple_struct_end(&mut self, state: State) -> Result<()>
fn serialize_tuple_struct_end(&mut self, state: State) -> Result<()>
Finishes serializing a tuple struct.
sourcefn serialize_tuple_variant(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize
) -> Result<State>
fn serialize_tuple_variant(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize
) -> Result<State>
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
sourcefn serialize_tuple_variant_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
fn serialize_tuple_variant_elt<T: Serialize>(
&mut self,
state: &mut State,
value: T
) -> Result<()>
Serializes a tuple variant element. Must have previously called
serialize_tuple_variant
. Read more
sourcefn serialize_tuple_variant_end(&mut self, state: State) -> Result<()>
fn serialize_tuple_variant_end(&mut self, state: State) -> Result<()>
Finishes serializing a tuple variant.
sourcefn serialize_map(&mut self, len: Option<usize>) -> Result<State>
fn serialize_map(&mut self, len: Option<usize>) -> Result<State>
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
sourcefn serialize_map_key<T: Serialize>(
&mut self,
state: &mut State,
key: T
) -> Result<()>
fn serialize_map_key<T: Serialize>(
&mut self,
state: &mut State,
key: T
) -> Result<()>
Serialize a map key. Must have previously called serialize_map
.
sourcefn serialize_map_value<T: Serialize>(
&mut self,
_: &mut State,
value: T
) -> Result<()>
fn serialize_map_value<T: Serialize>(
&mut self,
_: &mut State,
value: T
) -> Result<()>
Serialize a map value. Must have previously called serialize_map
.
sourcefn serialize_map_end(&mut self, state: State) -> Result<()>
fn serialize_map_end(&mut self, state: State) -> Result<()>
Finishes serializing a map.
sourcefn serialize_struct(&mut self, _name: &'static str, len: usize) -> Result<State>
fn serialize_struct(&mut self, _name: &'static str, len: usize) -> Result<State>
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
sourcefn serialize_struct_elt<V: Serialize>(
&mut self,
state: &mut State,
key: &'static str,
value: V
) -> Result<()>
fn serialize_struct_elt<V: Serialize>(
&mut self,
state: &mut State,
key: &'static str,
value: V
) -> Result<()>
Serializes a struct field. Must have previously called
serialize_struct
. Read more
sourcefn serialize_struct_end(&mut self, state: State) -> Result<()>
fn serialize_struct_end(&mut self, state: State) -> Result<()>
Finishes serializing a struct.
sourcefn serialize_struct_variant(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize
) -> Result<State>
fn serialize_struct_variant(
&mut self,
_name: &'static str,
_variant_index: usize,
variant: &'static str,
len: usize
) -> Result<State>
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
sourcefn serialize_struct_variant_elt<V: Serialize>(
&mut self,
state: &mut State,
key: &'static str,
value: V
) -> Result<()>
fn serialize_struct_variant_elt<V: Serialize>(
&mut self,
state: &mut State,
key: &'static str,
value: V
) -> Result<()>
Serialize a struct variant element. Must have previously called
serialize_struct_variant
. Read more
sourcefn serialize_struct_variant_end(&mut self, state: State) -> Result<()>
fn serialize_struct_variant_end(&mut self, state: State) -> Result<()>
Finishes serializing a struct variant.
Auto Trait Implementations
impl<W, F> RefUnwindSafe for Serializer<W, F> where
F: RefUnwindSafe,
W: RefUnwindSafe,
impl<W, F> Send for Serializer<W, F> where
F: Send,
W: Send,
impl<W, F> Sync for Serializer<W, F> where
F: Sync,
W: Sync,
impl<W, F> Unpin for Serializer<W, F> where
F: Unpin,
W: Unpin,
impl<W, F> UnwindSafe for Serializer<W, F> where
F: UnwindSafe,
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more