Struct Serializer
pub struct Serializer<'d> { /* private fields */ }
Serialization for TOML documents.
This structure implements serialization support for TOML to serialize an arbitrary type to TOML. Note that the TOML format does not support all datatypes in Rust, such as enums, tuples, and tuple structs. These types will generate an error when serialized.
Currently a serializer always writes its output to an in-memory String,
which is passed in when creating the serializer itself.
To serialize TOML values, instead of documents, see
[ValueSerializer][super::value::ValueSerializer].
Implementations
impl<'d> Serializer<'d>
fn new(buf: &'d mut Buffer) -> SelfCreates a new serializer which will emit TOML into the buffer provided.
The serializer can then be used to serialize a type after which the data will be present in
buf.fn pretty(buf: &'d mut Buffer) -> SelfApply a default "pretty" policy to the document
For greater customization, instead serialize to a
toml_edit::DocumentMut.
Trait Implementations
impl<'d> Serializer for Serializer<'d>
type Ok = &'d mut Buffer;type Error = Error;type SerializeSeq = Impossible<<Serializer<'d> as Serializer>::Ok, <Serializer<'d> as Serializer>::Error>;type SerializeTuple = Impossible<<Serializer<'d> as Serializer>::Ok, <Serializer<'d> as Serializer>::Error>;type SerializeTupleStruct = Impossible<<Serializer<'d> as Serializer>::Ok, <Serializer<'d> as Serializer>::Error>;type SerializeTupleVariant = SerializeDocumentTupleVariant<'d>;type SerializeMap = SerializeDocumentTable<'d>;type SerializeStruct = SerializeDocumentTable<'d>;type SerializeStructVariant = SerializeDocumentTable<'d>;fn serialize_bool(self, _v: bool) -> Result<Self::Ok, Self::Error>fn serialize_i8(self, _v: i8) -> Result<Self::Ok, Self::Error>fn serialize_i16(self, _v: i16) -> Result<Self::Ok, Self::Error>fn serialize_i32(self, _v: i32) -> Result<Self::Ok, Self::Error>fn serialize_i64(self, _v: i64) -> Result<Self::Ok, Self::Error>fn serialize_u8(self, _v: u8) -> Result<Self::Ok, Self::Error>fn serialize_u16(self, _v: u16) -> Result<Self::Ok, Self::Error>fn serialize_u32(self, _v: u32) -> Result<Self::Ok, Self::Error>fn serialize_u64(self, _v: u64) -> Result<Self::Ok, Self::Error>fn serialize_f32(self, _v: f32) -> Result<Self::Ok, Self::Error>fn serialize_f64(self, _v: f64) -> Result<Self::Ok, Self::Error>fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error>fn serialize_str(self, _v: &str) -> Result<Self::Ok, Self::Error>fn serialize_bytes(self, _v: &[u8]) -> Result<Self::Ok, Self::Error>fn serialize_none(self) -> Result<Self::Ok, Self::Error>fn serialize_some<T>(self, v: &T) -> Result<Self::Ok, Self::Error> where T: Serialize + ?Sized,fn serialize_unit(self) -> Result<Self::Ok, Self::Error>fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error>fn serialize_unit_variant(self, name: &'static str, _variant_index: u32, _variant: &'static str) -> Result<Self::Ok, Self::Error>fn serialize_newtype_struct<T>(self, _name: &'static str, v: &T) -> Result<Self::Ok, Self::Error> where T: Serialize + ?Sized,fn serialize_newtype_variant<T>(self, _name: &'static str, _variant_index: u32, variant: &'static str, value: &T) -> Result<Self::Ok, Self::Error> where T: Serialize + ?Sized,fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error>fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error>fn serialize_tuple_struct(self, _name: &'static str, len: usize) -> Result<Self::SerializeTupleStruct, Self::Error>fn serialize_tuple_variant(self, _name: &'static str, _variant_index: u32, variant: &'static str, len: usize) -> Result<Self::SerializeTupleVariant, Self::Error>fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error>fn serialize_struct(self, _name: &'static str, len: usize) -> Result<Self::SerializeStruct, Self::Error>fn serialize_struct_variant(self, _name: &'static str, _variant_index: u32, variant: &'static str, _len: usize) -> Result<Self::SerializeStructVariant, Self::Error>
Auto Trait Implementations
impl<'d> !UnwindSafe for Serializer<'d>
impl<'d> Freeze for Serializer<'d>
impl<'d> RefUnwindSafe for Serializer<'d>
impl<'d> Send for Serializer<'d>
impl<'d> Sync for Serializer<'d>
impl<'d> Unpin for Serializer<'d>
impl<'d> UnsafeUnpin for Serializer<'d>
Blanket Implementations
impl<T> Any for Serializer<'d>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Serializer<'d>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Serializer<'d>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for Serializer<'d>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for Serializer<'d>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Serializer<'d>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Serializer<'d>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>