| 1 |
use std::fmt; |
| 2 |
|
| 3 |
use winnow::error::{ContextError, ErrMode}; |
| 4 |
|
| 5 |
#[derive(Debug)] |
| 6 |
pub(crate) enum Error { |
| 7 |
ParseError(String), |
| 8 |
} |
| 9 |
|
| 10 |
impl std::error::Error for Error {} |
| 11 |
|
| 12 |
impl fmt::Display for Error { |
| 13 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 14 |
match self { |
| 15 |
Error::ParseError(reason) => { |
| 16 |
write!(f, "{reason}") |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl From<&'static str> for Error { |
| 23 |
fn from(reason: &'static str) -> Self { |
| 24 |
Error::ParseError(reason.to_owned()) |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
impl From<ErrMode<ContextError>> for Error { |
| 29 |
fn from(err: ErrMode<ContextError>) -> Self { |
| 30 |
Error::ParseError(err.to_string()) |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
impl From<jiff::Error> for Error { |
| 35 |
fn from(err: jiff::Error) -> Self { |
| 36 |
Error::ParseError(err.to_string()) |
| 37 |
} |
| 38 |
} |