[−][src]Trait amethyst_error::ResultExt
Extra convenience functions for results based on core errors.
Required methods
fn with_context<C, D>(self, chain: C) -> Result<T, Error> where
C: FnOnce(&Error) -> D,
D: Into<Error>,
C: FnOnce(&Error) -> D,
D: Into<Error>,
Provide a context for the result in case it is an error.
The context callback is expected to return a new error, which will replace the given error
and set the replaced error as its source
.
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"); assert_eq!("other", e.to_string()); assert_eq!("failing", e.source().expect("no source").to_string()); assert!(e.source().expect("no source").source().is_none());
Implementations on Foreign Types
impl<T, E> ResultExt<T> for Result<T, E> where
E: Into<Error>,
[src]
E: Into<Error>,
fn with_context<C, D>(self, chain: C) -> Result<T, Error> where
C: FnOnce(&Error) -> D,
D: Into<Error>,
[src]
C: FnOnce(&Error) -> D,
D: Into<Error>,