use core::any::TypeId;
pub trait Mode: Default + Clone + 'static {
fn is_panic(&self) -> bool {
TypeId::of::<Self>() == TypeId::of::<Panic>()
}
fn is_capture(&self) -> bool {
TypeId::of::<Self>() == TypeId::of::<Capture>()
}
fn set_derived(&mut self);
}
#[derive(Debug, Default, PartialEq, Clone)]
pub struct Panic {
pub(crate) derived: bool,
}
#[derive(Debug, Default, PartialEq, Clone)]
pub struct Capture {
pub(crate) derived: bool,
pub(crate) captured: bool,
}
impl Mode for Panic {
fn set_derived(&mut self) {
self.derived = true;
}
}
impl Mode for Capture {
fn set_derived(&mut self) {
self.derived = true;
}
}
impl Drop for Capture {
fn drop(&mut self) {
if !self.captured && !self.derived {
panic!(
"You dropped an `assert_that(..)` value, on which `.with_capture()` was called, without actually capturing the assertion failures using `.capture_failures()`!"
);
}
}
}