1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Type which will panic if dropped.
///
/// If this is dropped during a panic, this will cause an abort.
///
/// Use this to avoid letting unwinds cross through the FFI boundary, which is UB.
pub struct PanicTrap {
    msg: &'static str,
}

impl PanicTrap {
    #[inline]
    pub const fn new(msg: &'static str) -> Self {
        Self { msg }
    }

    #[inline]
    pub const fn disarm(self) {
        std::mem::forget(self)
    }
}

impl Drop for PanicTrap {
    fn drop(&mut self) {
        // Panic here will abort the process, assuming in an unwind.
        panic!("{}", self.msg)
    }
}
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here