pub struct DeserializerConfig { /* private fields */ }Expand description
Configures how CBOR 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 method
from_slice works like the function of the same
name. To read multiple data items with the configuration create a
Deserializer with Deserializer::from_slice_with_config.
use deser_cbor::DeserializerConfig;
const CONFIG: DeserializerConfig = DeserializerConfig::new();
assert_eq!(CONFIG.from_slice::<Vec<u32>>(&[0x82, 0x01, 0x02]).unwrap(), [1, 2]);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_slice<'de, T: Deserialize<'de>>(
&self,
input: &'de [u8],
) -> Result<T, Error>
pub fn from_slice<'de, T: Deserialize<'de>>( &self, input: &'de [u8], ) -> Result<T, Error>
Deserializes a value from CBOR.
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 stream of data items (see
deser::io::Reader).
See StreamDeserializer for how the stream is read.
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 data item from a reader.
See from_reader.