pub struct Fault {
pub source: Option<Box<dyn StdError + Send + Sync>>,
/* private fields */
}Expand description
Wrapper for errors that should not happen but cannot panic. It is wrapped in the Error::Fault variant.
To generate it from predicates use Fault::new, from Result or Option import the prelude and use either or_fault(), or_fault_no_source(), or_fault_force(), or_fault_no_source_force(), ok_or_fault() ok_or_fault_force()
Fields§
§source: Option<Box<dyn StdError + Send + Sync>>Implementations§
Source§impl Fault
impl Fault
Sourcepub fn with_source<E: StdError + 'static + Send + Sync>(self, error: E) -> Self
pub fn with_source<E: StdError + 'static + Send + Sync>(self, error: E) -> Self
Add an error source to a Fault. Usefull to generate a fault when pattern matching on an error type.
On a Result use map_err_or_fault to be more concise.
§Examples
fn fetch() -> Result<()> {
let sqlx_error = sqlx::Error::RowNotFound;
Err(match sqlx_error {
sqlx::Error::RowNotFound => MyEntitysError::NotFound.into(),
_ => Fault::new().with_source(sqlx_error).into()
})
}Sourcepub fn with_context(self, context: impl Display) -> Self
pub fn with_context(self, context: impl Display) -> Self
Sourcepub fn backtrace_status(&self) -> BacktraceStatus
pub fn backtrace_status(&self) -> BacktraceStatus
Return the status of the backtrace
Trait Implementations§
Source§impl Error for Fault
impl Error for Fault
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + '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§
impl !Freeze for Fault
impl !RefUnwindSafe for Fault
impl Send for Fault
impl Sync for Fault
impl Unpin for Fault
impl UnsafeUnpin for Fault
impl !UnwindSafe for Fault
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