36 lines
825 B
Rust
36 lines
825 B
Rust
![]() |
use {crate::prelude::ParseHostError, std::fmt};
|
||
|
|
||
|
#[derive(Debug, PartialEq)]
|
||
|
/// Errors which can occur when parsing a request
|
||
|
pub enum Error {
|
||
|
MissingSeparator,
|
||
|
EmptyUser,
|
||
|
EmptyHost,
|
||
|
EmptyMessage,
|
||
|
ParseHostError(ParseHostError),
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for Error {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||
|
match self {
|
||
|
Self::ParseHostError(e) => write!(f, "{e}"),
|
||
|
_ => write!(f, "{self:?}"),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl std::error::Error for Error {
|
||
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||
|
match self {
|
||
|
Self::ParseHostError(e) => Some(e),
|
||
|
_ => None,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<ParseHostError> for Error {
|
||
|
fn from(value: ParseHostError) -> Self {
|
||
|
Self::ParseHostError(value)
|
||
|
}
|
||
|
}
|