1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use nom::{error::ErrorKind, Err};
use alloc::borrow::ToOwned;
use alloc::string::String;
use core::fmt::{self, Display, Formatter};
#[derive(Debug)]
pub enum Error {
ParseError(String),
UnknownError,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::ParseError(msg) => f.write_str(msg),
Error::UnknownError => f.write_str("Unknown Error"),
}
}
}
#[cfg(feature = "std")]
impl alloc::error::Error for Error {}
impl From<Err<(&str, ErrorKind)>> for Error {
fn from(err: Err<(&str, ErrorKind)>) -> Self {
match err {
Err::Incomplete(_) => Error::UnknownError,
Err::Error((_, e)) => Error::ParseError(e.description().to_owned()),
Err::Failure((_, e)) => Error::ParseError(e.description().to_owned()),
}
}
}