Trait Error
trait Error: Debug + Display
Error is a trait representing the basic expectations for error values,
i.e., values of type E in [Result<T, E>].
Errors must describe themselves through the Display and Debug
traits. Error messages are typically concise lowercase sentences without
trailing punctuation:
let err = "NaN"..unwrap_err;
assert_eq!;
Error source
Errors may provide cause information. [Error::source()] is generally
used when errors cross "abstraction boundaries". If one module must report
an error that is caused by an error from a lower-level module, it can allow
accessing that error via Error::source(). This makes it possible for the
high-level module to provide its own errors while also revealing some of the
implementation for debugging.
In error types that wrap an underlying error, the underlying error
should be either returned by the outer error's Error::source(), or rendered
by the outer error's Display implementation, but not both.
Example
Implementing the Error trait only requires that Debug and Display are implemented too.
use Error;
use fmt;
use PathBuf;
Provided Methods
fn source(self: &Self) -> Option<&dyn Error + 'static>Returns the lower-level source of this error, if any.
Examples
use Error; use fmt; ;fn description(self: &Self) -> &strif let Err = "xc".fn cause(self: &Self) -> Option<&dyn Error>fn provide<'a>(self: &'a Self, request: &mut Request<'a>)Provides type-based access to context intended for error reports.
Used in conjunction with
Request::provide_valueandRequest::provide_refto extract references to member variables fromdyn Errortrait objects.Example
use fmt; use ;Delegating Impls
Warning: We recommend implementors avoid delegating implementations of
provideto source error implementations.This method should expose context from the current piece of the source chain only, not from sources that are exposed in the chain of sources. Delegating
provideimplementations cause the same context to be provided by multiple errors in the chain of sources which can cause unintended duplication of information in error reports or require heuristics to deduplicate.In other words, the following implementation pattern for
provideis discouraged and should not be used forErrortypes exposed in public APIs to third parties.# # use fmt; # use Request; # # # ; # # #
Implementors
impl Error for ParseBoolErrorimpl Error for crate::cell::BorrowMutErrorimpl Error for &strimpl Error for LayoutErrorimpl Error for crate::char::CharTryFromErrorimpl Error for AllocErrorimpl Error for crate::time::TryFromFloatSecsErrorimpl Error for crate::ffi::FromBytesUntilNulErrorimpl Error for crate::slice::GetDisjointMutErrorimpl Error for neverimpl Error for TryFromSliceErrorimpl Error for ParseCharErrorimpl Error for ParseIntErrorimpl Error for DecodeUtf16Errorimpl Error for TryFromCharErrorimpl<'a, T: Error + ?Sized> Error for &'a Timpl Error for Infallibleimpl Error for FromBytesWithNulErrorimpl Error for TryFromIntErrorimpl Error for crate::fmt::Errorimpl Error for AddrParseErrorimpl Error for crate::cell::BorrowErrorimpl Error for Utf8Error