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
impl IoError
Sourcepub fn new(message: impl Into<String>) -> Self
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).
Sourcepub fn with_source<E>(message: impl Into<String>, source: E) -> Self
pub fn with_source<E>(message: impl Into<String>, source: E) -> Self
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.
Sourcepub fn io_kind(&self) -> Option<ErrorKind>
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));Sourcepub fn is_timeout(&self) -> bool
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.
Sourcepub fn is_connection_refused(&self) -> bool
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.
Sourcepub fn is_connection_reset(&self) -> bool
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.
Sourcepub fn is_connection_aborted(&self) -> bool
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 Error for IoError
impl Error for IoError
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for IoError
impl From<Error> for IoError
Source§fn from(e: Error) -> Self
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.