Enum nom_errors::NomErr
source · pub enum NomErr<E, F> {
Error(E),
Failure(F),
}Variants§
Implementations§
source§impl<E, F> NomErr<E, F>
impl<E, F> NomErr<E, F>
sourcepub fn map_err<X>(self, f: impl FnOnce(E) -> X) -> NomErr<X, F>
pub fn map_err<X>(self, f: impl FnOnce(E) -> X) -> NomErr<X, F>
Examples found in repository?
src/lib.rs (line 31)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
pub fn any_err<E>(self) -> NomErr<E, F> {
self.map_err(|x| x)
}
}
impl<E> NomErr<E, !> {
pub fn any_fail<F>(self) -> NomErr<E, F> {
self.map_fail(|x| x)
}
}
impl<E> NomErr<E, E> {
pub fn fail(self) -> NomErr<!, E> {
match self {
NomErr::Error(e) => NomErr::Failure(e),
NomErr::Failure(e) => NomErr::Failure(e),
}
}
}
impl<I, E, F> ParseError<I> for NomErr<E, F> {
fn from_error_kind(_input: I, _kind: nom::error::ErrorKind) -> Self { panic!() }
fn append(_input: I, _kind: nom::error::ErrorKind, _other: Self) -> Self { panic!() }
fn or(self, _other: Self) -> Self { panic!() }
fn from_char(_input: I, _: char) -> Self { panic!() }
}
pub type NomRes<I, O, E, F> = IResult<I, O, NomErr<E, F>>;
pub fn parser_from_result<I, O, E, F>(r: Result<(I, O), NomErr<E, F>>) -> NomRes<I, O, E, F> {
match r {
Ok((i, o)) => Ok((i, o)),
Err(NomErr::Error(e)) => Err(nom::Err::Error(NomErr::Error(e))),
Err(NomErr::Failure(f)) => Err(nom::Err::Failure(NomErr::Failure(f))),
}
}
pub fn result_from_parser<I, O, E, F>(r: NomRes<I, O, E, F>) -> Result<(I, O), NomErr<E, F>> {
match r {
Ok((i, o)) => Ok((i, o)),
Err(nom::Err::Error(NomErr::Error(e))) => Err(NomErr::Error(e)),
Err(nom::Err::Failure(NomErr::Failure(e))) => Err(NomErr::Failure(e)),
_ => panic!()
}
}
pub fn map_err<I: Clone, O, E, F, X>(
mut parser: impl FnMut(I) -> NomRes<I, O, E, F>,
mut f: impl FnMut(E, I) -> X
) -> impl FnMut(I) -> NomRes<I, O, X, F> {
move |input: I| {
parser_from_result(result_from_parser(parser(input.clone())).map_err(|e| e.map_err(|e| f(e, input))))
}
}Trait Implementations§
source§impl<E: Ord, F: Ord> Ord for NomErr<E, F>
impl<E: Ord, F: Ord> Ord for NomErr<E, F>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<I, E, F> ParseError<I> for NomErr<E, F>
impl<I, E, F> ParseError<I> for NomErr<E, F>
source§fn from_error_kind(_input: I, _kind: ErrorKind) -> Self
fn from_error_kind(_input: I, _kind: ErrorKind) -> Self
Creates an error from the input position and an ErrorKind
source§fn append(_input: I, _kind: ErrorKind, _other: Self) -> Self
fn append(_input: I, _kind: ErrorKind, _other: Self) -> Self
Combines an existing error with a new one created from the input
position and an ErrorKind. This is useful when backtracking
through a parse tree, accumulating error context on the way
source§impl<E: PartialEq, F: PartialEq> PartialEq<NomErr<E, F>> for NomErr<E, F>
impl<E: PartialEq, F: PartialEq> PartialEq<NomErr<E, F>> for NomErr<E, F>
source§impl<E: PartialOrd, F: PartialOrd> PartialOrd<NomErr<E, F>> for NomErr<E, F>
impl<E: PartialOrd, F: PartialOrd> PartialOrd<NomErr<E, F>> for NomErr<E, F>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more