Trait Error
pub 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) -> Option<&dyn Error + 'static>Returns the lower-level source of this error, if any.
Examples
use Error; use fmt; ;fn type_id(&self, Internal) -> TypeId where Self: 'static,Gets the
TypeIdofself.fn description(&self) -> &strif let Err = "xc".fn cause(&self) -> Option<&dyn Error>fn provide<'a>(&'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 &strimpl Error for AddrParseErrorimpl Error for AllocErrorimpl Error for BorrowErrorimpl Error for BorrowMutErrorimpl Error for CharTryFromErrorimpl Error for DecodeUtf16Errorimpl Error for Errorimpl Error for Errorimpl Error for FromBytesUntilNulErrorimpl Error for FromBytesWithNulErrorimpl Error for GetDisjointMutErrorimpl Error for LayoutErrorimpl Error for ParseBoolErrorimpl Error for ParseCharErrorimpl Error for ParseFloatErrorimpl Error for ParseIntErrorimpl Error for TryFromCharErrorimpl Error for TryFromFloatSecsErrorimpl Error for TryFromIntErrorimpl Error for TryFromSliceErrorimpl Error for Utf8Errorimpl Error for neverimpl<'a, T: Error + ?Sized> Error for &'a T