Skip to main content

IoError

Struct IoError 

Source
pub struct IoError { /* private fields */ }
Expand description

A failure that originated below SMTP, in the transport (TCP, TLS, the runtime’s socket API).

Adapter crates (e.g. wasm-smtp-cloudflare, wasm-smtp-tokio) convert their runtime-specific errors into this type at the transport boundary. The wire-level details — the failing socket call, the underlying std::io::Error, the rustls handshake error — can optionally be preserved as the std::error::Error::source chain so callers see the full diagnostic when formatting the error chain.

§Backwards compatibility

The simplest constructor Self::new continues to accept any Display-able message and produces an IoError without a source. Adapters wishing to preserve the original cause should use Self::with_source (or the From<std::io::Error> impl).

§Example: preserving the io::Error in an adapter

use wasm_smtp::IoError;
use std::io;

fn map_tcp_failure(e: io::Error) -> IoError {
    IoError::with_source("TCP connect failed", e)
}

let original = io::Error::new(io::ErrorKind::ConnectionRefused, "refused");
let wrapped = map_tcp_failure(original);

// The high-level message is what Display shows:
assert_eq!(wrapped.to_string(), "TCP connect failed");

// The source chain still carries the original io::Error.
use std::error::Error;
assert!(wrapped.source().is_some());

Implementations§

Source§

impl IoError

Source

pub fn new(message: impl Into<String>) -> Self

Construct from any Display-able message, without an underlying source.

This is the simplest constructor and the right choice when the adapter does not have a structured error to preserve (e.g. when surfacing a programmer-supplied invariant violation).

Source

pub fn with_source<E>(message: impl Into<String>, source: E) -> Self
where E: StdError + Send + Sync + 'static,

Construct with a high-level message and an underlying error preserved as the std::error::Error::source chain.

Adapter crates use this to retain the original io::Error, rustls handshake error, etc. so caller-side error-chain formatters (anyhow’s {:#}, eyre, manual walks of .source()) can render the full diagnostic.

The Send + Sync + 'static bounds match the conventions of Box<dyn Error> carried across thread boundaries — important for tokio-based adapters where errors may surface on a different thread than the one that observed them.

Source

pub fn message(&self) -> &str

The human-readable description of the failure.

Source

pub fn io_kind(&self) -> Option<ErrorKind>

Walk the std::error::Error::source chain looking for an std::io::Error, then expose its std::io::ErrorKind.

Returns None when the chain contains no io::Error — for example, a TLS handshake error from rustls that did not wrap an underlying I/O error, or an IoError constructed via Self::new without a source.

This is the foundation for the is_* helpers below; callers who need a kind not covered by a named helper (e.g. std::io::ErrorKind::NotFound for a missing certificate file) can use io_kind directly.

§Example
let io = io::Error::new(io::ErrorKind::PermissionDenied, "no");
let wrapped = IoError::with_source("connect failed", io);
assert_eq!(wrapped.io_kind(), Some(io::ErrorKind::PermissionDenied));
Source

pub fn is_timeout(&self) -> bool

true when the underlying I/O error is a timeout (std::io::ErrorKind::TimedOut). Useful for retry-or-give-up decisions in retry layers.

Source

pub fn is_connection_refused(&self) -> bool

true when the underlying I/O error indicates the peer refused the connection (std::io::ErrorKind::ConnectionRefused). Typically means the server is down, the wrong port was used, or a firewall is blocking the connection.

Source

pub fn is_connection_reset(&self) -> bool

true when the underlying I/O error indicates the connection was reset by the peer (std::io::ErrorKind::ConnectionReset). Typically means the server hung up unexpectedly, often after an authentication failure or a protocol violation the server chose not to spell out.

Source

pub fn is_connection_aborted(&self) -> bool

true when the underlying I/O error indicates the connection was aborted (std::io::ErrorKind::ConnectionAborted).

Trait Implementations§

Source§

impl Debug for IoError

Source§

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

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

impl Display for IoError

Source§

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

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

impl Error for IoError

Source§

fn source(&self) -> Option<&(dyn StdError + '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<Error> for IoError

Source§

fn from(e: Error) -> Self

Convenience conversion: every adapter that wraps a std::io::Error can write io_error.into() to produce an IoError whose message is the original error’s Display and whose source chain preserves the original.

Most adapters will prefer IoError::with_source directly, because it lets them attach a higher-level context message (“TCP connect failed”, “TLS handshake failed”, “read short”) rather than relying on the often-terse io::Error Display.

Source§

impl From<IoError> for SmtpError

Source§

fn from(value: IoError) -> Self

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.