pub struct Serializer { /* private fields */ }Expand description
Serializes values into TOML.
A TOML document holds a single value, writing a second one fails.
use std::collections::BTreeMap;
use deser_toml::Serializer;
let mut serializer = Serializer::new();
serializer.serialize(&BTreeMap::from([("a", 1)])).unwrap();
assert!(serializer.serialize(&BTreeMap::from([("b", 2)])).is_err());
assert_eq!(serializer.finish(), "a = 1\n");The serializer is also the stream serializer of TOML (see
StreamSerializer). A TOML document cannot be
written in parts: the values of a table come before its subtables. To
write to a Write use SerializerConfig::writer.
Implementations§
Source§impl Serializer
impl Serializer
Sourcepub fn new() -> Serializer
pub fn new() -> Serializer
Creates a serializer.
Sourcepub fn with_config(config: SerializerConfig) -> Serializer
pub fn with_config(config: SerializerConfig) -> Serializer
Creates a serializer with the given configuration.
Sourcepub fn serialize<T: Serialize + ?Sized>(
&mut self,
value: &T,
) -> Result<(), Error>
pub fn serialize<T: Serialize + ?Sized>( &mut self, value: &T, ) -> Result<(), Error>
Serializes a value.
If the value fails to serialize, nothing is written.
Sourcepub fn serialize_with<F, T: Serialize + ?Sized>(
&mut self,
value: &T,
setup: F,
) -> Result<(), Error>where
F: FnOnce(&mut SerializeDriver<'_>),
pub fn serialize_with<F, T: Serialize + ?Sized>(
&mut self,
value: &T,
setup: F,
) -> Result<(), Error>where
F: FnOnce(&mut SerializeDriver<'_>),
Serializes a value with a configured driver.
The callback is invoked with the driver before the value is
serialized, for instance to add Layers.
Sourcepub fn config(&self) -> &SerializerConfig
pub fn config(&self) -> &SerializerConfig
Returns the configuration.
Trait Implementations§
Source§impl Clone for Serializer
impl Clone for Serializer
Source§impl Debug for Serializer
impl Debug for Serializer
Source§impl Default for Serializer
impl Default for Serializer
Source§fn default() -> Serializer
fn default() -> Serializer
Returns the “default value” for a type. Read more
Source§impl Serializer for Serializer
impl Serializer for Serializer
Source§fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
Receives the events of a value from the driver and writes them into
the output.
Source§fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
Serializes a value with a configured driver. Read more
Source§fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
Serializes the value of a reference. Read more
Source§impl StreamSerializer for Serializer
impl StreamSerializer for Serializer
Source§fn output(&self) -> &[u8] ⓘ
fn output(&self) -> &[u8] ⓘ
Returns the bytes serialized so far which were not cleared yet. Read more
Source§fn clear_output(&mut self)
fn clear_output(&mut self)
Discards the bytes returned by
output, for
instance because they were written.Source§fn supports_partial(&self) -> bool
fn supports_partial(&self) -> bool
Source§fn drive_partial(
&mut self,
driver: &mut SerializeDriver<'_>,
limit: usize,
) -> Result<bool, Error>
fn drive_partial( &mut self, driver: &mut SerializeDriver<'_>, limit: usize, ) -> Result<bool, Error>
Serializes a value, or a part of it, and appends its bytes to the
output. Read more
Source§fn in_progress(&self) -> bool
fn in_progress(&self) -> bool
Returns
true if a value is partially serialized. Read moreAuto Trait Implementations§
impl Freeze for Serializer
impl RefUnwindSafe for Serializer
impl Send for Serializer
impl Sync for Serializer
impl Unpin for Serializer
impl UnsafeUnpin for Serializer
impl UnwindSafe for Serializer
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