Trait unwind_context::PanicDetector
source · pub trait PanicDetector {
// Required method
fn is_panicking(&self) -> bool;
}
Expand description
An utility trait which is used to detect panic.
§Examples
use core::sync::atomic::{self, AtomicBool};
use unwind_context::unwind_context_with_fmt;
#[derive(Copy, Clone, Debug)]
pub struct NoStdPanicFlag<'a>(&'a AtomicBool);
impl unwind_context::PanicDetector for NoStdPanicFlag<'_> {
fn is_panicking(&self) -> bool {
self.0.load(atomic::Ordering::Relaxed)
}
}
fn func(foo: u32, bar: &str, writer: &mut String, panic_flag: NoStdPanicFlag<'_>) {
let ctx =
unwind_context_with_fmt!((foo, bar), writer = writer, panic_detector = panic_flag,);
// ...
}
Required Methods§
sourcefn is_panicking(&self) -> bool
fn is_panicking(&self) -> bool
Determines whether the current thread is unwinding because of panic.
§Panics
Implementations should generally avoid panic!
ing, because
is_panicking()
may itself be called during unwinding due to a
panic, and if the is_panicking()
panics in that situation (a “double
panic”), this will likely abort the program.
Implementors§
impl PanicDetector for StdPanicDetector
Available on crate feature
std
only.