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
impl Error
Sourcepub fn new<E>(error: E) -> Self
pub fn new<E>(error: E) -> Self
Default constructor for our error types.
Wraps anything that is an error in a box.
Sourcepub fn with_source<S>(self, source: S) -> Self
pub fn with_source<S>(self, source: S) -> Self
Update the source of an error.
Sourcepub fn from_string<M>(message: M) -> Self
pub fn from_string<M>(message: M) -> Self
Construct a new error from a string.
Sourcepub fn source(&self) -> Option<&Error>
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());
Sourcepub fn causes(&self) -> Causes<'_> ⓘ
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);
Sourcepub fn as_error(&self) -> &(dyn Error + 'static)
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more