Combine the error types.
This commit is contained in:
25
src/error/error.rs
Normal file
25
src/error/error.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use nom::error::ErrorKind;
|
||||
use nom::error::ParseError;
|
||||
use nom::IResult;
|
||||
|
||||
pub type Res<T, U> = IResult<T, U, CustomError<T>>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum CustomError<I> {
|
||||
MyError(MyError<I>),
|
||||
Nom(I, ErrorKind),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct MyError<I>(pub I);
|
||||
|
||||
impl<I> ParseError<I> for CustomError<I> {
|
||||
fn from_error_kind(input: I, kind: ErrorKind) -> Self {
|
||||
CustomError::Nom(input, kind)
|
||||
}
|
||||
|
||||
fn append(_input: I, _kind: ErrorKind, mut other: Self) -> Self {
|
||||
// Doesn't do append like VerboseError
|
||||
other
|
||||
}
|
||||
}
|
||||
4
src/error/mod.rs
Normal file
4
src/error/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
mod error;
|
||||
pub use error::CustomError;
|
||||
pub use error::MyError;
|
||||
pub use error::Res;
|
||||
Reference in New Issue
Block a user