[][src]Struct amethyst_error::Error

pub struct Error { /* fields omitted */ }

The error type used by Amethyst.

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


impl Error[src]

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.

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

Update the source of an error.

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

Construct a new error from a string.

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

Get backtrace.

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

Get the source of the error.


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());

pub fn causes(&self) -> Causes[src]

Iterate over all causes, including this one.


use amethyst_error::{Error, ResultExt};

fn failing_function() -> Result<(), Error> {

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

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

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

impl Debug for Error[src]

impl Display for Error[src]

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

Blanket implementation.

Encapsulate errors which are Send + Sync.

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

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

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

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> ToString for T where
    T: Display + ?Sized

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.