Function no_std_compat::panic::take_hook

1.10.0 · source ·
pub fn take_hook() -> Box<dyn Fn(&PanicHookInfo<'_>) + Send + Sync>
Expand description

Unregisters the current panic hook and returns it, registering the default hook in its place.

See also the function set_hook.

If the default hook is registered it will be returned, but remain registered.

§Panics

Panics if called from a panicking thread.

§Examples

The following will print “Normal panic”:

use std::panic;

panic::set_hook(Box::new(|_| {
    println!("Custom panic hook");
}));

let _ = panic::take_hook();

panic!("Normal panic");