//! Serializing Rust structures into TOML. //! //! This module contains all the Serde support for serializing Rust structures //! into TOML documents (as strings). Note that some top-level functions here //! are also provided at the top of the crate.
mod array; mod array_of_tables; mod buffer; mod map; mod strategy;
use toml_writer::TomlWrite as _;
usesuper::style; usesuper::value; usesuper::Error; usecrate::alloc_prelude::*; use buffer::Table; use strategy::SerializationStrategy;
pubuse buffer::Buffer;
/// 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]. pubstruct Serializer<'d> {
buf: &'d mut Buffer,
style: style::Style,
table: Table,
}
impl<'d> Serializer<'d> { /// Creates 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`. pubfn new(buf: &'d mut Buffer) -> Self { let table = buf.root_table(); Self {
buf,
style: Default::default(),
table,
}
}
/// Apply a default "pretty" policy to the document /// /// For greater customization, instead serialize to a /// [`toml_edit::DocumentMut`](https://docs.rs/toml_edit/latest/toml_edit/struct.DocumentMut.html). pubfn pretty(buf: &'d mut Buffer) -> Self { letmut ser = Serializer::new(buf);
ser.style.multiline_array = true;
ser
}
impl<'d> serde_core::ser::Serializer for Serializer<'d> { type Ok = &'d mut Buffer; type Error = Error; type SerializeSeq = serde_core::ser::Impossible<Self::Ok, Self::Error>; type SerializeTuple = serde_core::ser::Impossible<Self::Ok, Self::Error>; type SerializeTupleStruct = serde_core::ser::Impossible<Self::Ok, Self::Error>; type SerializeTupleVariant = array::SerializeDocumentTupleVariant<'d>; type SerializeMap = map::SerializeDocumentTable<'d>; type SerializeStruct = map::SerializeDocumentTable<'d>; type SerializeStructVariant = map::SerializeDocumentTable<'d>;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.