devela/code/result/panic/
namespace.rs
1#[cfg(feature = "std")]
8use crate::{
9 Any, Box, PanicHookInfo, PanicUnwindSafe, ThreadResult,
10 _dep::_std::panic::{catch_unwind, panic_any, resume_unwind, set_hook, take_hook},
11};
12
13#[doc = crate::TAG_NAMESPACE!()]
14pub struct Panic;
16
17#[cfg(feature = "std")]
18#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "std")))]
19impl Panic {
20 pub fn catch<F: FnOnce() -> R + PanicUnwindSafe, R>(f: F) -> ThreadResult<R> {
24 catch_unwind(f)
25 }
26
27 pub fn any<M: 'static + Any + Send>(msg: M) -> ! {
31 panic_any(msg)
32 }
33
34 pub fn resume(payload: Box<dyn Any + Send>) -> ! {
38 resume_unwind(payload)
39 }
40
41 pub fn set_hook(hook: Box<dyn Fn(&PanicHookInfo<'_>) + Sync + Send + 'static>) {
43 set_hook(hook);
44 }
45
46 pub fn take_hook() -> Box<dyn Fn(&PanicHookInfo<'_>) + Sync + Send + 'static> {
48 take_hook()
49 }
50}