Struct futures_ext::future::SharedError
source · pub struct SharedError { /* private fields */ }
Expand description
SharedError is a simple, cloneable anyhow::Error
wrapper.
It holds the inner error in an Arc<anyhow::Error>
to support Clone.
Propagation of errors via ?
converts automatically
to SharedError.
use shared_error::anyhow::*;
use ::anyhow::Error;
use thiserror::Error;
#[derive(Debug, Error)]
enum SomeErrorType {
#[error("Some error variant: {0}")]
SomeErrorVariant(String),
}
fn some_fallible_func() -> Result<(), SharedError> {
let result: Result<(), SomeErrorType> =
Err(SomeErrorType::SomeErrorVariant("some context".to_owned()));
Ok(result.shared_error()?)
}
fn some_fallible_func_anyhow() -> Result<(), SharedError> {
let result: Result<(), Error> =
Err(SomeErrorType::SomeErrorVariant("some context".to_owned()).into());
Ok(result.shared_error()?)
}
fn some_caller() {
let result = some_fallible_func();
match result {
Ok(_) => { /* do something */ },
Err(shared_error) => {
// some_func_1_that_consumes_error(shared_error.clone());
// ...
// some_func_N_that_consumes_error(shared_error.clone());
}
}
let _result = some_fallible_func_anyhow();
}
Implementations§
sourcepub fn new_arcederror(error: Arc<Error>) -> SharedError
pub fn new_arcederror(error: Arc<Error>) -> SharedError
Creates a new arced error
Trait Implementations§
source§fn clone(&self) -> SharedError
fn clone(&self) -> SharedError
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
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
Method to convert std and anyhow Errors into SharedError.