2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-02-21 03:39:40 +00:00
async-std/src/utils.rs

22 lines
406 B
Rust
Raw Normal View History

2019-08-08 12:44:48 +00:00
use std::mem;
use std::process;
/// Calls a function and aborts if it panics.
///
/// This is useful in unsafe code where we can't recover from panics.
#[inline]
pub fn abort_on_panic<T>(f: impl FnOnce() -> T) -> T {
struct Bomb;
impl Drop for Bomb {
fn drop(&mut self) {
process::abort();
}
}
let bomb = Bomb;
let t = f();
mem::forget(bomb);
t
}