Skip to main content

NetError

Enum NetError 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Bind

Binding failed for a reason without its own variant; source has the OS error.

Fields

§addr: SocketAddr

The address that could not be bound.

§source: Error

The OS error.

§

AddrInUse

Another socket holds the address.

Fields

§addr: SocketAddr

The address in use.

§

AddrNotAvailable

The address is not on this host, or IPv6 is disabled.

Fields

§addr: SocketAddr

The address that is not available.

§

PermissionDenied

The OS refused the operation for lack of permission.

Fields

§what: &'static str

What was refused.

§

NoAddresses

Name resolution returned no address.

§

ConnectTimeout

No answer from the peer within the connect deadline.

Fields

§addr: SocketAddr

The address that did not answer.

§after: Duration

How long the attempt waited.

§

ConnectionRefused

Nothing listens at the address.

Fields

§addr: SocketAddr

The address that refused.

§

HostUnreachable

No route to the host.

Fields

§addr: SocketAddr

The unreachable address.

§

NetworkUnreachable

No route to the network.

Fields

§addr: SocketAddr

The unreachable address.

§

TimedOut

One of net-io’s deadlines passed.

Fields

§kind: TimeoutKind

Which 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: KillReason

The caller’s code.

§

EgressDenied

The gate denied a write; the connection was reset.

Fields

§code: u16

The gate’s code.

§

Refused

The connection was refused.

Fields

§cause: RefusalCause

Why.

§

Limit

A configured bound was hit.

Fields

§which: LimitKind

Which bound.

§

SlowPeer

The minimum transfer rate was not met.

Fields

§direction: Direction

In which direction.

§

InvalidConfig

A builder or option value is out of range or inconsistent.

Fields

§field: &'static str

The setter or field that holds the value.

§reason: ConfigReason

The rule it broke.

§

Unsupported

The platform lacks the feature.

Fields

§feature: &'static str

The feature.

§platform: &'static str

The platform.

§

PathTooLong

A Unix socket path exceeds the platform limit.

Fields

§max: usize

The limit in bytes, including the terminator.

§

StaleSocketInUse

A live listener owns the socket path, or the path is not a socket.

Fields

§path: PathBuf

The path.

§

PipeNameInUse

Another process created the named pipe first.

Fields

§name: String

The pipe name.

§

NotFound

No local endpoint with that name.

§

FileTruncated

A file shrank while it was being sent.

Fields

§sent: u64

Bytes sent before the file ended.

§

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.

Fields

§driver: DriverKind

The driver that failed.

§source: Error

The OS error.

§

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.

Fields

§op: &'static str

The operation that failed.

§source: Error

The OS error.

Implementations§

Source§

impl NetError

Source

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);
Source

pub fn is_retryable(&self) -> bool

Whether retrying the same operation later can succeed.

use net_io::NetError;
assert!(!NetError::ConnectionReset.is_retryable());
Source

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 Debug for NetError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NetError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for NetError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<AddrError> for NetError

Source§

fn from(e: AddrError) -> NetError

Converts to this type from the input type.
Source§

impl From<Error> for NetError

Source§

fn from(e: Error) -> NetError

Converts to this type from the input type.
Source§

impl From<NetError> for Error

Source§

fn from(e: NetError) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.