tokio-gemini/src/error.rs

68 lines
1.4 KiB
Rust
Raw Normal View History

2024-08-01 09:32:55 +03:00
#[derive(Debug)]
2024-07-31 21:14:29 +03:00
pub enum LibError {
IoError(std::io::Error),
InvalidUrlError(InvalidUrl),
StatusOutOfRange(u8),
MessageNotUtf8(std::string::FromUtf8Error),
BodyNotUtf8(std::str::Utf8Error),
InvalidMime(mime::FromStrError),
2024-07-31 21:14:29 +03:00
}
impl From<std::io::Error> for LibError {
#[inline]
fn from(err: std::io::Error) -> Self {
Self::IoError(err)
}
}
impl From<url::ParseError> for LibError {
#[inline]
fn from(err: url::ParseError) -> Self {
Self::InvalidUrlError(InvalidUrl::ParseError(err))
}
}
impl From<InvalidUrl> for LibError {
#[inline]
fn from(err: InvalidUrl) -> Self {
Self::InvalidUrlError(err)
}
}
impl LibError {
#[inline]
pub fn status_out_of_range(num: u8) -> Self {
Self::StatusOutOfRange(num)
}
}
impl From<std::string::FromUtf8Error> for LibError {
#[inline]
fn from(err: std::string::FromUtf8Error) -> Self {
Self::MessageNotUtf8(err)
}
}
impl From<std::str::Utf8Error> for LibError {
#[inline]
fn from(err: std::str::Utf8Error) -> Self {
Self::BodyNotUtf8(err)
}
}
impl From<mime::FromStrError> for LibError {
#[inline]
fn from(err: mime::FromStrError) -> Self {
Self::InvalidMime(err)
}
}
2024-08-01 09:32:55 +03:00
#[derive(Debug)]
2024-07-31 21:14:29 +03:00
pub enum InvalidUrl {
ParseError(url::ParseError),
SchemeNotGemini,
UserinfoPresent,
NoHostFound,
ConvertError,
}