amethyst_error

Struct Error

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

The error type used by Amethyst.

Wraps error diagnostics like messages and other errors, and keeps track of causal chains and backtraces.

Implementations§

Source§

impl Error

Source

pub fn new<E>(error: E) -> Self
where E: 'static + Error + Send + Sync,

Default constructor for our error types.

Wraps anything that is an error in a box.

Source

pub fn with_source<S>(self, source: S) -> Self
where S: 'static + Into<Error>,

Update the source of an error.

Source

pub fn from_string<M>(message: M) -> Self
where M: Into<Cow<'static, str>>,

Construct a new error from a string.

Source

pub fn backtrace(&self) -> Option<&Backtrace>

Get backtrace.

Source

pub fn source(&self) -> Option<&Error>

Get the source of the error.

§Examples

The source can be set using with_source or through ResultExt using with_context.

use amethyst_error::{Error, ResultExt};
use std::io;

let e = io::Error::new(io::ErrorKind::Other, "wrapped");
let a = Error::new(e);

let res = Result::Err::<(), Error>(a).with_context(|_| Error::from_string("top"));
let e = res.expect_err("no error");

assert_eq!("top", e.to_string());
assert_eq!("wrapped", e.source().expect("no source").to_string());
Source

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

Iterate over all causes, including this one.

§Examples
use amethyst_error::{Error, ResultExt};

fn failing_function() -> Result<(), Error> {
    Err(Error::from_string("failing"))
}

fn other_function() -> Result<(), Error> {
    Ok(failing_function().with_context(|_| Error::from_string("other"))?)
}

let e = other_function().expect_err("no error");

let messages = e.causes().map(|e| e.to_string()).collect::<Vec<_>>();
assert_eq!(vec!["other", "failing"], messages);
Source

pub fn as_error(&self) -> &(dyn Error + 'static)

Access the internal std::error::Error as a trait.

This can be useful for integrating with systems that operate on std::error::Error.

Warning: This erases most diagnostics in favor of returning only the top error. std::error::Error is expanded further.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl<T> From<T> for Error
where T: 'static + Error + Send + Sync,

Blanket implementation.

Encapsulate errors which are Send + Sync.

Source§

fn from(value: T) -> Error

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> ToString for T
where 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 T
where U: Into<T>,

Source§

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

Source§

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.