organic/src/error/error.rs

38 lines
849 B
Rust
Raw Normal View History

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-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)]
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-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)
}
fn append(_input: I, _kind: ErrorKind, /*mut*/ other: Self) -> Self {
// 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-10-17 09:45:18 -04:00
impl From<&'static str> for CustomError {
fn from(value: &'static str) -> Self {
2023-10-17 09:45:18 -04:00
CustomError::Static(value)
}
}