use thiserror::Error;
pub type Result<T> = std::result::Result<T, TransportError>;
#[derive(Error, Debug)]
pub enum TransportError {
#[error("connection failed: {0}")]
ConnectionFailed(String),
#[error("connection closed")]
ConnectionClosed,
#[error("bind failed: {0}")]
BindFailed(String),
#[error("accept failed: {0}")]
AcceptFailed(String),
#[error("send failed: {0}")]
SendFailed(String),
#[error("send buffer full")]
BufferFull,
#[error("receive failed: {0}")]
ReceiveFailed(String),
#[error("invalid url: {0}")]
InvalidUrl(String),
#[error("timeout")]
Timeout,
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("protocol error: {0}")]
Protocol(String),
#[error("not connected")]
NotConnected,
#[error("already connected")]
AlreadyConnected,
#[error("transport error: {0}")]
Other(String),
}
#[cfg(feature = "websocket")]
impl From<tokio_tungstenite::tungstenite::Error> for TransportError {
fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
TransportError::Other(e.to_string())
}
}