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