Function panic_control::chain_hook_ignoring [] [src]

pub fn chain_hook_ignoring<P: 'static>()

Augments the panic hook, filtering out panics of a particular type.

The current panic hook, either installed with std::panic::set_hook() or the standard library default, gets chained, again using std::panic::set_hook(), behind a dynamic type check for the panic payload. If it is found to be of the same type as the type parameter of this generic function, the chained hook is not called.

Caveats

Every call to this function allocates state data and increases the filtering chain for the process-global panic hook, so it should not be called repeatedly unless necessary. Other code within the program that modifies the panic hook, concurrently to, or after, the call to this function, may cause the hook chain to stop working as intended. This function interoperates in a predictable way only with the other functions and methods of this crate that modify the panic hook, and only when used in strictly serialized order with those functions, unless noted otherwise in those functions' documentation. This function is only intended to be used in tests or initialization code of a program; libraries other than those designed for test purposes should avoid using it.

Examples

use panic_control::chain_hook_ignoring;
use std::sync::{Once, ONCE_INIT};

#[derive(Debug, PartialEq, Eq)]
struct PanicToken;

#[derive(Debug, PartialEq, Eq)]
struct PanicMessage(pub String);

static HOOK_ONCE: Once = ONCE_INIT;
HOOK_ONCE.call_once(|| {
    chain_hook_ignoring::<PanicToken>();
    chain_hook_ignoring::<PanicMessage>();
});