1use derive_more::From;
2
3pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug, From)]
8pub enum Error {
9 #[from]
11 Custom(String),
12 #[from]
15 Io(std::io::Error),
16 #[from]
18 Nom(nom::error::Error<&'static str>),
19 StreamComplete,
22 UnexpectedEof,
24 WriteHeadersAfterRecords,
26 NomFailed(String),
28}
29
30impl Error {
31 pub fn custom(val: impl std::fmt::Display) -> Self {
33 Self::Custom(val.to_string())
34 }
35}
36
37impl From<&str> for Error {
38 fn from(val: &str) -> Self {
39 Self::Custom(val.to_string())
40 }
41}
42
43impl core::fmt::Display for Error {
44 fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> {
45 write!(fmt, "{self:?}")
46 }
47}
48
49impl std::error::Error for Error {}