pub struct Error { /* private fields */ }Expand description
I/O error mirroring std::io::Error.
Carries an ErrorKind plus an optional message string for
context. The rendered Display form is "<kind>" when no
message is attached, or "<kind>: <message>" when one is.
Under feature = "std", the From<std::io::Error> bridge
below applies a tri-state message-attachment policy so the
rendered text matches the information density of the input
without paying a heap allocation for plain kind-only inputs:
- std error carries context (
raw_os_error.is_some()ORget_ref().is_some()— the canonical std discriminator for “more than just a kind”) — the stdDisplayoutput is captured as the message. The original OS / errno / path text survives the conversion and appears after the kind tag. - std error is plain kind-only AND we mapped the kind
(
std::io::Error::from(ErrorKind::NotFound)etc.) — no message is attached. The kind tag already conveys the information; capturing the stdDisplayoutput would just repeat it ("entity not found: entity not found") and burn a heap allocation on the hot path. - std error is plain kind-only but we did NOT map the
kind (the
#[non_exhaustive]std::io::ErrorKindcatch-all branch — e.g.OutOfMemorymapping to ourErrorKind::Other) — the stdDisplayoutput IS captured so the user-visible discriminant isn’t lost in theOtherbucket. Renders as"other error: out of memory"rather than just"other error".
Implementations§
Source§impl Error
impl Error
Sourcepub fn new<M: Into<String>>(kind: ErrorKind, message: M) -> Self
pub fn new<M: Into<String>>(kind: ErrorKind, message: M) -> Self
Construct an error with the given kind and a context message.
Analogous to std::io::Error::new but intentionally
narrower: this constructor takes a String-coercible
message and stores it verbatim, where std’s new()
accepts E: Into<Box<dyn std::error::Error + Send + Sync>>
and carries a chained source via Error::source(). This
crate’s error type has no source-chaining surface (and
can’t have one under no_std + alloc without an alloc
dyn-trait shim), so an analogous “wrap an inner error”
helper would be misleading; callers wanting the source
payload of a std error use the From<std::io::Error>
bridge below, which renders the std Display into the
message field.
Sourcepub const fn from_kind(kind: ErrorKind) -> Self
pub const fn from_kind(kind: ErrorKind) -> Self
Construct an error with only an ErrorKind (no message).
Matches std::io::Error::from for ErrorKind.
Sourcepub fn other<M: Into<String>>(message: M) -> Self
pub fn other<M: Into<String>>(message: M) -> Self
Construct an ErrorKind::Other error carrying message.
Mirrors std::io::Error::other.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · 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()
Source§impl From<Error> for Error
Available on crate feature std only.Bridge from std::io::Error. Maps the std ErrorKind to
this crate’s ErrorKind when a variant exists for it, and
falls back to ErrorKind::Other for any std variant we
don’t track (the std type is #[non_exhaustive], so the
catch-all is required). The Display message is captured via
the tri-state policy documented on Error: kept for
contextful std errors and for unmapped kinds (so the
discriminant is preserved even in the Other bucket),
dropped for plain kind-only errors whose kind we DO map (to
avoid the redundant "<kind>: <kind>" render and the heap
allocation). Net effect: ? from std-backed backends
propagates the original context to operators, but callers
inspecting err.kind() after the conversion should be aware
that an unknown std kind now reads as
ErrorKind::Other rather than the originating variant.
impl From<Error> for Error
std only.Bridge from std::io::Error. Maps the std ErrorKind to
this crate’s ErrorKind when a variant exists for it, and
falls back to ErrorKind::Other for any std variant we
don’t track (the std type is #[non_exhaustive], so the
catch-all is required). The Display message is captured via
the tri-state policy documented on Error: kept for
contextful std errors and for unmapped kinds (so the
discriminant is preserved even in the Other bucket),
dropped for plain kind-only errors whose kind we DO map (to
avoid the redundant "<kind>: <kind>" render and the heap
allocation). Net effect: ? from std-backed backends
propagates the original context to operators, but callers
inspecting err.kind() after the conversion should be aware
that an unknown std kind now reads as
ErrorKind::Other rather than the originating variant.
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more