#[non_exhaustive]pub enum NetError {
Show 35 variants
Bind {
addr: SocketAddr,
source: Error,
},
AddrInUse {
addr: SocketAddr,
},
AddrNotAvailable {
addr: SocketAddr,
},
PermissionDenied {
what: &'static str,
},
NoAddresses,
ConnectTimeout {
addr: SocketAddr,
after: Duration,
},
ConnectionRefused {
addr: SocketAddr,
},
HostUnreachable {
addr: SocketAddr,
},
NetworkUnreachable {
addr: SocketAddr,
},
TimedOut {
kind: TimeoutKind,
},
ConnectionReset,
BrokenPipe,
Closed,
Killed {
reason: KillReason,
},
EgressDenied {
code: u16,
},
Refused {
cause: RefusalCause,
},
Limit {
which: LimitKind,
},
SlowPeer {
direction: Direction,
},
InvalidConfig {
field: &'static str,
reason: ConfigReason,
},
Unsupported {
feature: &'static str,
platform: &'static str,
},
PathTooLong {
max: usize,
},
StaleSocketInUse {
path: PathBuf,
},
PipeNameInUse {
name: String,
},
NotFound,
FileTruncated {
sent: u64,
},
Address(AddrError),
Proxy(ProxyError),
Tls(TlsError),
Inherit(InheritError),
Handoff(HandoffError),
DriverSetup {
driver: DriverKind,
source: Error,
},
DoorClosed,
ShuttingDown,
ForkedChild,
Os {
op: &'static str,
source: Error,
},
}Expand description
The one error type of the crate.
Every variant’s Display says what happened and what to do about it.
§Examples
use net_io::{ErrorClass, NetError};
match net_io::connect("127.0.0.1:9") {
Ok(_) => {}
Err(NetError::ConnectionRefused { addr }) => eprintln!("nothing listens on {addr}"),
Err(e) if e.class() == ErrorClass::Timeout => eprintln!("slow network: {e}"),
Err(e) => return Err(e),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Bind
Binding failed for a reason without its own variant; source has the OS error.
AddrInUse
Another socket holds the address.
Fields
addr: SocketAddrThe address in use.
AddrNotAvailable
The address is not on this host, or IPv6 is disabled.
Fields
addr: SocketAddrThe address that is not available.
PermissionDenied
The OS refused the operation for lack of permission.
NoAddresses
Name resolution returned no address.
ConnectTimeout
No answer from the peer within the connect deadline.
Fields
addr: SocketAddrThe address that did not answer.
ConnectionRefused
Nothing listens at the address.
Fields
addr: SocketAddrThe address that refused.
HostUnreachable
No route to the host.
Fields
addr: SocketAddrThe unreachable address.
NetworkUnreachable
No route to the network.
Fields
addr: SocketAddrThe unreachable address.
TimedOut
One of net-io’s deadlines passed.
Fields
kind: TimeoutKindWhich deadline.
ConnectionReset
The peer reset the connection.
BrokenPipe
A write after the peer closed the connection.
Closed
The connection was already closed by this side or the peer.
Killed
A kill handle closed the connection.
Fields
reason: KillReasonThe caller’s code.
EgressDenied
The gate denied a write; the connection was reset.
Refused
The connection was refused.
Fields
cause: RefusalCauseWhy.
Limit
A configured bound was hit.
SlowPeer
The minimum transfer rate was not met.
InvalidConfig
A builder or option value is out of range or inconsistent.
Fields
reason: ConfigReasonThe rule it broke.
Unsupported
The platform lacks the feature.
PathTooLong
A Unix socket path exceeds the platform limit.
StaleSocketInUse
A live listener owns the socket path, or the path is not a socket.
PipeNameInUse
Another process created the named pipe first.
NotFound
No local endpoint with that name.
FileTruncated
A file shrank while it was being sent.
Address(AddrError)
An address, CIDR block, or trusted-proxy list did not parse.
Proxy(ProxyError)
A PROXY protocol header was invalid.
Tls(TlsError)
The TLS engine failed.
Inherit(InheritError)
Inherited descriptors failed verification.
Handoff(HandoffError)
A listener hand-off failed; nothing was adopted.
DriverSetup
The selected driver could not start.
DoorClosed
The operation needs the door open.
ShuttingDown
The server is draining or stopped.
ForkedChild
A server was used in a process created by fork after it was built.
Os
Any other OS failure.
Implementations§
Source§impl NetError
impl NetError
Sourcepub fn class(&self) -> ErrorClass
pub fn class(&self) -> ErrorClass
The broad kind of this error.
use net_io::{ErrorClass, NetError, TimeoutKind};
assert_eq!(NetError::TimedOut { kind: TimeoutKind::Read }.class(), ErrorClass::Timeout);Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether retrying the same operation later can succeed.
use net_io::NetError;
assert!(!NetError::ConnectionReset.is_retryable());Sourcepub fn os_error_code(&self) -> Option<i32>
pub fn os_error_code(&self) -> Option<i32>
The raw OS error number, when the error came from the OS.
use net_io::NetError;
assert_eq!(NetError::Closed.os_error_code(), None);Trait Implementations§
Source§impl Error for NetError
impl Error for NetError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()