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 duplicate 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)>
Returns 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Method to convert std and anyhow Errors into SharedError.