[−][src]Struct failure::Error
The Error
type, which can contain any failure.
Functions which accumulate many kinds of errors should return this type.
All failures can be converted into it, so functions which catch those
errors can be tried with ?
inside of a function that returns this kind
of error.
In addition to implementing Debug
and Display
, this type carries Backtrace
information, and can be downcast into the failure that underlies it for
more detailed inspection.
Methods
impl Error
[src]
impl Error
pub fn from_boxed_compat(err: Box<StdError + Sync + Send + 'static>) -> Error
[src]
pub fn from_boxed_compat(err: Box<StdError + Sync + Send + 'static>) -> Error
Creates an Error
from Box<std::error::Error>
.
This method is useful for comparability with code,
which does not use the Fail
trait.
Example
use std::error::Error as StdError; use failure::Error; fn app_fn() -> Result<i32, Error> { let x = library_fn().map_err(Error::from_boxed_compat)?; Ok(x * 2) } fn library_fn() -> Result<i32, Box<StdError + Sync + Send + 'static>> { Ok(92) }
pub fn as_fail(&self) -> &Fail
[src]
pub fn as_fail(&self) -> &Fail
Return a reference to the underlying failure that this Error
contains.
pub fn cause(&self) -> &Fail
[src]
pub fn cause(&self) -> &Fail
: please use 'as_fail()' method instead
Returns a reference to the underlying cause of this Error
. Unlike the
method on Fail
, this does not return an Option
. The Error
type
always has an underlying failure.
This method has been deprecated in favor of the Error::as_fail method, which does the same thing.
pub fn backtrace(&self) -> &Backtrace
[src]
pub fn backtrace(&self) -> &Backtrace
Gets a reference to the Backtrace
for this Error
.
If the failure this wrapped carried a backtrace, that backtrace will
be returned. Otherwise, the backtrace will have been constructed at
the point that failure was cast into the Error
type.
pub fn context<D: Display + Send + Sync + 'static>(
self,
context: D
) -> Context<D>
[src]
pub fn context<D: Display + Send + Sync + 'static>(
self,
context: D
) -> Context<D>
Provides context for this Error
.
This can provide additional information about this error, appropriate to the semantics of the current layer. That is, if you have a lower-level error, such as an IO error, you can provide additional context about what that error means in the context of your function. This gives users of this function more information about what has gone wrong.
This takes any type that implements Display
, as well as
Send
/Sync
/'static
. In practice, this means it can take a String
or a string literal, or a failure, or some other custom context-carrying
type.
pub fn compat(self) -> Compat<Error>
[src]
pub fn compat(self) -> Compat<Error>
Wraps Error
in a compatibility type.
This type implements the Error
trait from std::error
. If you need
to pass failure's Error
to an interface that takes any Error
, you
can use this method to get a compatible type.
pub fn downcast<T: Fail>(self) -> Result<T, Error>
[src]
pub fn downcast<T: Fail>(self) -> Result<T, Error>
Attempts to downcast this Error
to a particular Fail
type.
This downcasts by value, returning an owned T
if the underlying
failure is of the type T
. For this reason it returns a Result
- in
the case that the underlying error is of a different type, the
original Error
is returned.
pub fn find_root_cause(&self) -> &Fail
[src]
pub fn find_root_cause(&self) -> &Fail
Returns the "root cause" of this error - the last value in the
cause chain which does not return an underlying cause
.
ⓘImportant traits for Causes<'f>pub fn iter_causes(&self) -> Causes
[src]
pub fn iter_causes(&self) -> Causes
Returns a iterator over the causes of this error with the cause
of the fail as the first item and the root_cause
as the final item.
Use iter_chain
to also include the fail of this error itself.
ⓘImportant traits for Causes<'f>pub fn iter_chain(&self) -> Causes
[src]
pub fn iter_chain(&self) -> Causes
Returns a iterator over all fails up the chain from the current
as the first item up to the root_cause
as the final item.
This means that the chain also includes the fail itself which
means that it does not start with cause
. To skip the outermost
fail use iter_causes
instead.
pub fn downcast_ref<T: Fail>(&self) -> Option<&T>
[src]
pub fn downcast_ref<T: Fail>(&self) -> Option<&T>
Attempts to downcast this Error
to a particular Fail
type by
reference.
If the underlying error is not of type T
, this will return None
.
pub fn downcast_mut<T: Fail>(&mut self) -> Option<&mut T>
[src]
pub fn downcast_mut<T: Fail>(&mut self) -> Option<&mut T>
Attempts to downcast this Error
to a particular Fail
type by
mutable reference.
If the underlying error is not of type T
, this will return None
.
pub fn root_cause(&self) -> &Fail
[src]
pub fn root_cause(&self) -> &Fail
: please use the 'find_root_cause()' method instead
Deprecated alias to find_root_cause
.
ⓘImportant traits for Causes<'f>pub fn causes(&self) -> Causes
[src]
pub fn causes(&self) -> Causes
: please use the 'iter_chain()' method instead
Deprecated alias to iter_causes
.
Trait Implementations
impl<T> ResultExt<T, Error> for Result<T, Error>
[src]
impl<T> ResultExt<T, Error> for Result<T, Error>
fn compat(self) -> Result<T, Compat<Error>>
[src]
fn compat(self) -> Result<T, Compat<Error>>
Wraps the error in Compat
to make it compatible with older error handling APIs that expect std::error::Error
. Read more
fn context<D>(self, context: D) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
[src]
fn context<D>(self, context: D) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
Wraps the error type in a context type. Read more
fn with_context<F, D>(self, f: F) -> Result<T, Context<D>> where
F: FnOnce(&Error) -> D,
D: Display + Send + Sync + 'static,
[src]
fn with_context<F, D>(self, f: F) -> Result<T, Context<D>> where
F: FnOnce(&Error) -> D,
D: Display + Send + Sync + 'static,
Wraps the error type in a context type generated by looking at the error value. Read more
impl AsRef<Fail + 'static> for Error
[src]
impl AsRef<Fail + 'static> for Error
impl From<Error> for Box<StdError>
[src]
impl From<Error> for Box<StdError>
impl<F: Fail> From<F> for Error
[src]
impl<F: Fail> From<F> for Error
impl Display for Error
[src]
impl Display for Error
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Debug for Error
[src]
impl Debug for Error
Auto Trait Implementations
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more