Files
organic/src/error/error.rs

36 lines
867 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 {
2024-04-11 20:57:11 -04:00
Static(#[allow(dead_code)] &'static str),
IO(#[allow(dead_code)] std::io::Error),
Parser(#[allow(dead_code)] 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)
}
}