pub struct Bug {
pub source: Option<Box<dyn Error>>,
/* 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::Bug variant.
To generate it from predicates use Bug::new, from Result or Option import the prelude and use either bug(), bug_no_source(), bug_force(), bug_no_source_force()
Fields§
§source: Option<Box<dyn Error>>Implementations§
Source§impl Bug
impl Bug
Sourcepub fn with_source<E>(self, error: E) -> Bugwhere
E: Error + 'static,
pub fn with_source<E>(self, error: E) -> Bugwhere
E: Error + 'static,
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) -> Bug
pub fn with_context(self, context: impl Display) -> Bug
Trait Implementations§
Source§impl Error for Bug
impl Error for Bug
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 Bug
impl Serialize for Bug
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 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