pub struct Errors<T, R, P> {
pub position: P,
pub errors: Vec<Error<T, R>>,
}
Expand description
Struct which hold information about an error that occurred at a specific position.
Can hold multiple instances of Error
if more that one error occurred in the same position.
Fields§
§position: P
The position where the error occurred
errors: Vec<Error<T, R>>
A vector containing specific information on what errors occurred at position
. Usually
a fully formed message contains one Unexpected
error and one or more Expected
errors.
Message
and Other
may also appear (combine
never generates these errors on its own)
and may warrant custom handling.
Implementations§
source§impl<T, R, P> Errors<T, R, P>
impl<T, R, P> Errors<T, R, P>
sourcepub fn new(position: P, error: Error<T, R>) -> Errors<T, R, P>
pub fn new(position: P, error: Error<T, R>) -> Errors<T, R, P>
Constructs a new ParseError
which occurred at position
.
sourcepub fn empty(position: P) -> Errors<T, R, P>
pub fn empty(position: P) -> Errors<T, R, P>
Constructs an error with no other information than the position it occurred at.
sourcepub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P>
pub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P>
Constructs a ParseError
with multiple causes.
sourcepub fn end_of_input(position: P) -> Errors<T, R, P>
pub fn end_of_input(position: P) -> Errors<T, R, P>
Constructs an end of input error. Should be returned by parsers which encounter end of input unexpectedly.
sourcepub fn add_error(&mut self, error: Error<T, R>)
pub fn add_error(&mut self, error: Error<T, R>)
Adds an error if error
does not exist in this ParseError
already (as determined byte
PartialEq
).
sourcepub fn set_expected(&mut self, info: Info<T, R>)
pub fn set_expected(&mut self, info: Info<T, R>)
Removes all Expected
errors in self
and adds info
instead.
sourcepub fn merge(self, other: Errors<T, R, P>) -> Errors<T, R, P>
pub fn merge(self, other: Errors<T, R, P>) -> Errors<T, R, P>
Merges two ParseError
s. If they exist at the same position the errors of other
are
added to self
(using add_error
to skip duplicates). If they are not at the same
position the error furthest ahead are returned, ignoring the other ParseError
.
sourcepub fn map_position<F, Q>(self, f: F) -> Errors<T, R, Q>where
F: FnOnce(P) -> Q,
pub fn map_position<F, Q>(self, f: F) -> Errors<T, R, Q>where
F: FnOnce(P) -> Q,
Maps the position to a new value
Trait Implementations§
source§impl<T, R, P> Error for Errors<T, R, P>
impl<T, R, P> Error for Errors<T, R, P>
source§fn description(&self) -> &str
fn description(&self) -> &str
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
source§impl<Item, Range, Position> ParseError<Item, Range, Position> for Errors<Item, Range, Position>
impl<Item, Range, Position> ParseError<Item, Range, Position> for Errors<Item, Range, Position>
type StreamError = Error<Item, Range>
source§fn from_error(position: Position, err: Self::StreamError) -> Self
fn from_error(position: Position, err: Self::StreamError) -> Self
ParseError
from a single Self::StreamError
fn position(&self) -> Position
source§fn set_position(&mut self, position: Position)
fn set_position(&mut self, position: Position)
ParseError
source§fn merge(self, other: Self) -> Self
fn merge(self, other: Self) -> Self
other
are
added to self
(using the semantics of add
). If they are not at the same
position the error furthest ahead are returned, ignoring the other ParseError
.source§fn add(&mut self, err: Self::StreamError)
fn add(&mut self, err: Self::StreamError)
source§fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
info
as the only Expected
error of self
source§fn clear_expected(&mut self)
fn clear_expected(&mut self)
self
fn is_unexpected_end_of_input(&self) -> bool
source§fn into_other<T>(self) -> Twhere
T: ParseError<Item, Range, Position>,
fn into_other<T>(self) -> Twhere
T: ParseError<Item, Range, Position>,
self
into another ParseError