use std::fmt;
pub type TransportResult<T> = Result<T, TransportError>;
#[derive(Debug)]
pub enum TransportError {
Config(String),
Connection(String),
Send(String),
Recv(String),
Commit(String),
Closed,
Timeout,
Backpressure,
Internal(String),
Admin(String),
}
impl fmt::Display for TransportError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Config(msg) => write!(f, "transport config error: {msg}"),
Self::Connection(msg) => write!(f, "transport connection error: {msg}"),
Self::Send(msg) => write!(f, "transport send error: {msg}"),
Self::Recv(msg) => write!(f, "transport receive error: {msg}"),
Self::Commit(msg) => write!(f, "transport commit error: {msg}"),
Self::Closed => write!(f, "transport closed"),
Self::Timeout => write!(f, "transport operation timed out"),
Self::Backpressure => write!(f, "transport backpressure"),
Self::Internal(msg) => write!(f, "transport internal error: {msg}"),
Self::Admin(msg) => write!(f, "transport admin error: {msg}"),
}
}
}
impl std::error::Error for TransportError {}
impl TransportError {
#[must_use]
pub fn is_recoverable(&self) -> bool {
matches!(self, Self::Timeout | Self::Backpressure)
}
#[must_use]
pub fn is_fatal(&self) -> bool {
matches!(self, Self::Closed | Self::Config(_))
}
}