2023-04-11 14:50:37 -04:00
|
|
|
use nom::error::ErrorKind;
|
|
|
|
use nom::error::ParseError;
|
|
|
|
use nom::IResult;
|
|
|
|
|
2023-10-17 09:45:18 -04:00
|
|
|
pub(crate) type Res<T, U> = IResult<T, U, CustomError>;
|
2023-04-11 14:50:37 -04:00
|
|
|
|
2023-09-04 16:53:02 -04:00
|
|
|
#[derive(Debug)]
|
2023-10-17 09:45:18 -04:00
|
|
|
pub enum CustomError {
|
2023-10-17 10:39:21 -04:00
|
|
|
#[allow(dead_code)]
|
2023-10-17 09:27:15 -04:00
|
|
|
Text(String),
|
2023-10-17 09:45:18 -04:00
|
|
|
Static(&'static str),
|
2023-09-04 16:53:02 -04:00
|
|
|
IO(std::io::Error),
|
2023-10-17 10:35:33 -04:00
|
|
|
Parser(ErrorKind),
|
2023-04-11 14:50:37 -04:00
|
|
|
}
|
|
|
|
|
2023-10-17 09:45:18 -04:00
|
|
|
impl<I: std::fmt::Debug> ParseError<I> for CustomError {
|
2023-10-17 10:39:21 -04:00
|
|
|
fn from_error_kind(_input: I, kind: ErrorKind) -> Self {
|
2023-10-17 10:35:33 -04:00
|
|
|
CustomError::Parser(kind)
|
2023-04-11 14:50:37 -04:00
|
|
|
}
|
|
|
|
|
2023-04-21 18:42:31 -04:00
|
|
|
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
|
2023-04-11 14:50:37 -04:00
|
|
|
// Doesn't do append like VerboseError
|
|
|
|
other
|
|
|
|
}
|
|
|
|
}
|
2023-09-04 16:53:02 -04:00
|
|
|
|
2023-10-17 09:45:18 -04:00
|
|
|
impl From<std::io::Error> for CustomError {
|
2023-09-04 16:53:02 -04:00
|
|
|
fn from(value: std::io::Error) -> Self {
|
|
|
|
CustomError::IO(value)
|
|
|
|
}
|
|
|
|
}
|
2023-09-29 11:26:23 -04:00
|
|
|
|
2023-10-17 09:45:18 -04:00
|
|
|
impl From<&'static str> for CustomError {
|
2023-09-29 11:26:23 -04:00
|
|
|
fn from(value: &'static str) -> Self {
|
2023-10-17 09:45:18 -04:00
|
|
|
CustomError::Static(value)
|
2023-09-29 11:26:23 -04:00
|
|
|
}
|
|
|
|
}
|