1use std::any::Any;
6use std::panic::{self, AssertUnwindSafe};
7use std::thread;
8
9pub(super) fn halt_unwinding<F, R>(func: F) -> thread::Result<R>
14where
15    F: FnOnce() -> R,
16{
17    panic::catch_unwind(AssertUnwindSafe(func))
18}
19
20pub(super) fn resume_unwinding(payload: Box<dyn Any + Send>) -> ! {
21    panic::resume_unwind(payload)
22}
23
24pub(super) struct AbortIfPanic;
25
26impl Drop for AbortIfPanic {
27    fn drop(&mut self) {
28        eprintln!("Rayon: detected unexpected panic; aborting");
29        ::std::process::abort();
30    }
31}