pub struct Fault {
pub source: Option<Box<dyn Error + Sync + Send>>,
/* private fields */
}
Expand description
Re-import from explicit_error crate. 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 Error + Sync + Send>>
Implementations§
Source§impl Fault
impl Fault
Sourcepub fn with_source<E>(self, error: E) -> Fault
pub fn with_source<E>(self, error: E) -> Fault
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) -> Fault
pub fn with_context(self, context: impl Display) -> Fault
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 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()
Source§impl Serialize for Fault
impl Serialize for Fault
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl !Freeze for Fault
impl !RefUnwindSafe for Fault
impl Send for Fault
impl Sync for Fault
impl Unpin 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