pub struct TrackLocations(pub bool);Expand description
Asks the formats to provide the Source (a value of the
Context).
Formats publish the byte range of every event, resolving them into
lines and columns (for instance with the Spanned type of
deser-location) also requires the
source, which is a copy of the input. Formats only provide it if this
is set to true in the context (or the state). The errors a
deserialization fails with have their line and column either way, but
for instance the keys collected with
UnknownFields::Collect only
have them with the source:
use deser::de::{Deserializer, IgnoredFields, UnknownFields};
use deser::{Context, Deserialize, TrackLocations};
#[derive(Deserialize)]
struct Config {
name: String,
}
let config = deser_json::DeserializerConfig::builder()
.context(Context::with(TrackLocations(true)))
.build();
let input = "{\n \"name\": \"demo\",\n \"nmae\": \"x\"\n}";
let ignored = IgnoredFields::new();
deser_json::Deserializer::from_str_with_config(input, config)
.deserialize_with::<Config, _>(|driver| {
UnknownFields::Collect(ignored.clone()).set(driver.state_mut())
})
.unwrap();
let ignored = ignored.take();
assert_eq!((ignored[0].line(), ignored[0].column()), (Some(3), Some(3)));Formats check this with of and set the Source before
they emit the first event:
use deser::de::{DeserializeDriver, Deserializer};
use deser::{Error, Source, TrackLocations};
/// A format which provides the source if asked to.
struct Text<'a>(&'a str);
impl<'de> Deserializer<'de> for Text<'de> {
fn drive(&mut self, driver: &mut DeserializeDriver<'_, 'de>) -> Result<(), Error> {
if TrackLocations::of(driver.state()) {
Source(self.0.into()).set(driver.state_mut());
}
driver.state_mut().set_input_range(0, self.0.len());
driver.emit(self.0)
}
}Tuple Fields§
§0: boolImplementations§
Trait Implementations§
Source§impl Clone for TrackLocations
impl Clone for TrackLocations
impl Copy for TrackLocations
Source§impl Debug for TrackLocations
impl Debug for TrackLocations
Source§impl Default for TrackLocations
impl Default for TrackLocations
impl Eq for TrackLocations
Source§impl PartialEq for TrackLocations
impl PartialEq for TrackLocations
impl StructuralPartialEq for TrackLocations
Auto Trait Implementations§
impl Freeze for TrackLocations
impl RefUnwindSafe for TrackLocations
impl Send for TrackLocations
impl Sync for TrackLocations
impl Unpin for TrackLocations
impl UnsafeUnpin for TrackLocations
impl UnwindSafe for TrackLocations
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.