hyperi_rustlib/transport/
error.rs1use std::fmt;
10
11pub type TransportResult<T> = Result<T, TransportError>;
13
14#[derive(Debug)]
16pub enum TransportError {
17 Config(String),
19
20 Connection(String),
22
23 Send(String),
25
26 Recv(String),
28
29 Commit(String),
31
32 Closed,
34
35 Timeout,
37
38 Backpressure,
40
41 Internal(String),
43
44 Admin(String),
46}
47
48impl fmt::Display for TransportError {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 match self {
51 Self::Config(msg) => write!(f, "transport config error: {msg}"),
52 Self::Connection(msg) => write!(f, "transport connection error: {msg}"),
53 Self::Send(msg) => write!(f, "transport send error: {msg}"),
54 Self::Recv(msg) => write!(f, "transport receive error: {msg}"),
55 Self::Commit(msg) => write!(f, "transport commit error: {msg}"),
56 Self::Closed => write!(f, "transport closed"),
57 Self::Timeout => write!(f, "transport operation timed out"),
58 Self::Backpressure => write!(f, "transport backpressure"),
59 Self::Internal(msg) => write!(f, "transport internal error: {msg}"),
60 Self::Admin(msg) => write!(f, "transport admin error: {msg}"),
61 }
62 }
63}
64
65impl std::error::Error for TransportError {}
66
67impl TransportError {
68 #[must_use]
70 pub fn is_recoverable(&self) -> bool {
71 matches!(self, Self::Timeout | Self::Backpressure)
72 }
73
74 #[must_use]
76 pub fn is_fatal(&self) -> bool {
77 matches!(self, Self::Closed | Self::Config(_))
78 }
79}