pub struct CollectedErrors { /* private fields */ }Expand description
The errors a map or sequence collected from its items.
This is a helper for sinks that collect the errors of their items (see
State::set_collect_errors). In Sink::recover
the error is passed to collect, which keeps it if
errors are collected. Once the container is complete,
finish fails with all errors that were collected:
use deser::de::{CollectedErrors, Deserialize, Sink, SinkHandle};
use deser::{Error, State};
struct Numbers(Vec<u32>);
struct NumbersSink<'a> {
out: &'a mut Option<Numbers>,
numbers: Vec<u32>,
current: Option<u32>,
errors: CollectedErrors,
}
impl<'a> NumbersSink<'a> {
fn flush(&mut self) {
self.numbers.extend(self.current.take());
}
}
impl<'de> Sink<'de> for NumbersSink<'_> {
fn seq(&mut self, _state: &mut State) -> Result<(), Error> {
Ok(())
}
fn next_value(
&mut self,
state: &mut State,
) -> Result<SinkHandle<'_, 'de>, Error> {
self.flush();
Ok(u32::deserialize_into(&mut self.current, state))
}
fn recover(
&mut self,
err: Error,
state: &mut State,
) -> Result<(), Error> {
self.current = None;
self.errors.collect(err, state)
}
fn finish(&mut self, _state: &mut State) -> Result<(), Error> {
self.errors.finish()?;
self.flush();
*self.out = Some(Numbers(std::mem::take(&mut self.numbers)));
Ok(())
}
}Implementations§
Source§impl CollectedErrors
impl CollectedErrors
Sourcepub const fn new() -> CollectedErrors
pub const fn new() -> CollectedErrors
Creates an empty list of errors.
Sourcepub fn collect(&mut self, err: Error, state: &mut State) -> Result<(), Error>
pub fn collect(&mut self, err: Error, state: &mut State) -> Result<(), Error>
Collects the error of an item if errors are collected.
If errors are not collected (or the limit of errors is reached, see
State::set_max_errors), the error is returned together with the
errors collected so far. Errors which do not have the context of an
event attached yet (see Error) get the context of the current
event.
Sourcepub fn push(&mut self, err: Error, state: &State)
pub fn push(&mut self, err: Error, state: &State)
Adds an error that is not the error of an item.
This is for errors that are found once the container is complete, for instance missing fields. They are always added and do not count towards the limit of errors. Errors which do not have the context of an event attached yet get the context of the current event.