use core::fmt;
use tokio_tungstenite::tungstenite::Error as WsError;
use url::ParseError;
#[derive(Debug)]
pub enum Error {
Ws(WsError),
Io(std::io::Error),
#[cfg(feature = "socks")]
Socks(tokio_socks::Error),
Url(ParseError),
Timeout,
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Ws(e) => write!(f, "{e}"),
Self::Io(e) => write!(f, "{e}"),
#[cfg(feature = "socks")]
Self::Socks(e) => write!(f, "{e}"),
Self::Url(e) => write!(f, "{e}"),
Self::Timeout => write!(f, "timeout"),
}
}
}
impl From<WsError> for Error {
fn from(e: WsError) -> Self {
Self::Ws(e)
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
#[cfg(feature = "socks")]
impl From<tokio_socks::Error> for Error {
fn from(e: tokio_socks::Error) -> Self {
Self::Socks(e)
}
}
impl Error {
#[inline]
pub(super) fn empty_host() -> Self {
Self::Url(ParseError::EmptyHost)
}
#[inline]
pub(super) fn invalid_port() -> Self {
Self::Url(ParseError::InvalidPort)
}
}