pub struct Error { /* private fields */ }
Expand description

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.

Implementations

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)
}

Return a reference to the underlying failure that this Error contains.

Returns the name of the underlying fail.

👎Deprecated since 0.1.2:

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.

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.

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.

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.

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.

Returns the “root cause” of this error - the last value in the cause chain which does not return an underlying cause.

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.

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.

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.

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.

👎Deprecated since 0.1.2:

please use the ‘find_root_cause()’ method instead

Deprecated alias to find_root_cause.

👎Deprecated since 0.1.2:

please use the ‘iter_chain()’ method instead

Deprecated alias to iter_causes.

Trait Implementations

Converts a reference to Self into a dynamic trait object of Fail.

Converts this type into a shared reference of the (usually inferred) input type.

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.