Skip to main content

Error

Struct Error 

Source
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:

  1. std error carries context (raw_os_error.is_some() OR get_ref().is_some() — the canonical std discriminator for “more than just a kind”) — the std Display output is captured as the message. The original OS / errno / path text survives the conversion and appears after the kind tag.
  2. 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 std Display output would just repeat it ("entity not found: entity not found") and burn a heap allocation on the hot path.
  3. std error is plain kind-only but we did NOT map the kind (the #[non_exhaustive] std::io::ErrorKind catch-all branch — e.g. OutOfMemory mapping to our ErrorKind::Other) — the std Display output IS captured so the user-visible discriminant isn’t lost in the Other bucket. Renders as "other error: out of memory" rather than just "other error".

Implementations§

Source§

impl Error

Source

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.

Source

pub const fn from_kind(kind: ErrorKind) -> Self

Construct an error with only an ErrorKind (no message). Matches std::io::Error::from for ErrorKind.

Source

pub const fn kind(&self) -> ErrorKind

Return the ErrorKind this error carries.

Source

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

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

1.30.0 · 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<Error> for Error

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
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.

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Available on crate feature std only.

Bridge back to std::io::Error so existing call sites that consume std::io::Result<_> (and where From is invoked via ?) keep compiling once their input switches to this module.

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ErrorKind> for Error

Source§

fn from(kind: ErrorKind) -> Self

Converts to this type from the input type.

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V