pub struct DeserializerConfig { /* private fields */ }Expand description
Configures how TOML is deserialized.
The configuration is independent of the input so it can be created once
(even as a constant) and used for many inputs. The methods
from_str and from_slice work
like the functions of the same name. To create a Deserializer with
the configuration use Deserializer::from_str_with_config or
Deserializer::from_slice_with_config. The only option is the
Context (see set_context),
which holds what is configured from the outside (like
TrackLocations).
use std::collections::BTreeMap;
use deser_toml::DeserializerConfig;
const CONFIG: DeserializerConfig = DeserializerConfig::new();
let value: BTreeMap<String, u32> = CONFIG.from_str("a = 1").unwrap();
assert_eq!(value["a"], 1);Implementations§
Source§impl DeserializerConfig
impl DeserializerConfig
Sourcepub const fn new() -> DeserializerConfig
pub const fn new() -> DeserializerConfig
Creates the default configuration.
Sourcepub const fn builder() -> DeserializerConfigBuilder
pub const fn builder() -> DeserializerConfigBuilder
Returns a builder for the configuration (see DeserializerConfigBuilder).
Sourcepub const fn into_builder(self) -> DeserializerConfigBuilder
pub const fn into_builder(self) -> DeserializerConfigBuilder
Returns a builder that starts with this configuration.
Sourcepub fn set_context(&mut self, context: Context)
pub fn set_context(&mut self, context: Context)
Sets the context the values are deserialized in.
The values of the context are the defaults of the extension values
of the state (see Context), for instance
the variants of open enums. The deserializers and readers created
with the configuration use this context. A context set
on the driver takes precedence.
Sourcepub fn from_str<'de, T: Deserialize<'de>>(
&self,
s: &'de str,
) -> Result<T, Error>
pub fn from_str<'de, T: Deserialize<'de>>( &self, s: &'de str, ) -> Result<T, Error>
Deserializes a value from TOML.
See from_str.
Sourcepub fn from_slice<'de, T: Deserialize<'de>>(
&self,
bytes: &'de [u8],
) -> Result<T, Error>
pub fn from_slice<'de, T: Deserialize<'de>>( &self, bytes: &'de [u8], ) -> Result<T, Error>
Deserializes a value from TOML in a byte slice.
See from_slice.
Source§impl DeserializerConfig
impl DeserializerConfig
Sourcepub fn reader<R: Read>(&self, reader: R) -> Reader<R, StreamDeserializer>
pub fn reader<R: Read>(&self, reader: R) -> Reader<R, StreamDeserializer>
Creates a reader of a TOML document (see
deser::io::Reader).
See StreamDeserializer.
Sourcepub fn from_reader<T: DeserializeOwned, R: Read>(
&self,
reader: R,
) -> Result<T, Error>
pub fn from_reader<T: DeserializeOwned, R: Read>( &self, reader: R, ) -> Result<T, Error>
Deserializes a document from a reader.
See from_reader.