pub struct Deserializer<'a> { /* private fields */ }Expand description
Deserializes types from a Value.
This is a Deserializer which emits the
events of a value. It’s what
from_value uses, use it directly to configure the deserialization,
for instance to add layers:
use std::collections::BTreeMap;
use deser_path::{Path, PathLayer};
use deser_value::{value, Deserializer};
let value = value!({"items": [1, "two"]});
let err = Deserializer::new(&value)
.deserialize_with::<BTreeMap<String, Vec<u32>>, _>(|driver| {
driver.push_layer(PathLayer::new());
})
.unwrap_err();
assert_eq!(err.attachment::<Path>().unwrap().to_string(), "items[1]");Strings and bytes are passed on borrowed from the value, which means
that types like &str can be deserialized. The meta data
of the values is restored for every event: event data is attached and if
the value has spans, the input ranges and the source are published.
This means that errors refer to the location in the input the value was
deserialized from.
Implementations§
Source§impl<'a> Deserializer<'a>
impl<'a> Deserializer<'a>
Sourcepub fn new(value: &'a Value) -> Deserializer<'a>
pub fn new(value: &'a Value) -> Deserializer<'a>
Creates a deserializer for a value.
Sourcepub fn deserialize<T: Deserialize<'a>>(&mut self) -> Result<T, Error>
pub fn deserialize<T: Deserialize<'a>>(&mut self) -> Result<T, Error>
Deserializes the value.
Sourcepub fn deserialize_with<T, F>(&mut self, setup: F) -> Result<T, Error>
pub fn deserialize_with<T, F>(&mut self, setup: F) -> Result<T, Error>
Deserializes the value with a configured driver.
The callback is invoked with the driver before the value is
deserialized, for instance to add Layers.
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). A context set
on the driver (for instance in the setup callback of deserialize_with)
takes precedence.