Struct sn0int::errors::Error

source ·
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§

source§

impl Error

source

pub fn from_boxed_compat(err: Box<dyn Error + Send + Sync, Global>) -> 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)
}
source

pub fn as_fail(&self) -> &(dyn Fail + 'static)

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

source

pub fn name(&self) -> Option<&str>

Returns the name of the underlying fail.

source

pub fn cause(&self) -> &(dyn Fail + 'static)

👎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.

source

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.

source

pub fn context<D>(self, context: D) -> Context<D>where D: Display + Send + Sync + 'static,

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.

source

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.

source

pub fn downcast<T>(self) -> Result<T, Error>where T: Fail,

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.

source

pub fn find_root_cause(&self) -> &(dyn Fail + 'static)

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

source

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.

source

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.

source

pub fn downcast_ref<T>(&self) -> Option<&T>where T: Fail,

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.

source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: Fail,

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.

source

pub fn root_cause(&self) -> &(dyn Fail + 'static)

👎Deprecated since 0.1.2: please use the ‘find_root_cause()’ method instead

Deprecated alias to find_root_cause.

source

pub fn causes(&self) -> Causes<'_>

👎Deprecated since 0.1.2: please use the ‘iter_chain()’ method instead

Deprecated alias to iter_causes.

Trait Implementations§

source§

impl AsFail for Error

source§

fn as_fail(&self) -> &(dyn Fail + 'static)

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

impl AsRef<dyn Fail> for Error

source§

fn as_ref(&self) -> &(dyn Fail + 'static)

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

impl Debug for Error

source§

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

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

impl Display for Error

source§

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

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

impl<F> From<F> for Errorwhere F: Fail,

source§

fn from(failure: F) -> Error

Converts to this type from the input type.
source§

impl<T> ResultExt<T, Error> for Result<T, Error>

source§

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
source§

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
source§

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> IntoSql for T

source§

fn into_sql<T>(self) -> Self::Expressionwhere Self: AsExpression<T> + Sized,

Convert self to an expression for Diesel’s query builder. Read more
source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere &'a Self: AsExpression<T>,

Convert &self to an expression for Diesel’s query builder. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V

§

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool