From 30d0f08b6073e9c2e545a3567838a9e1e885fea2 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 23 Dec 2024 15:31:07 -0500 Subject: Remove scopeguard The scopeguard crate was being used for its `defer_on_unwind` macro. The problem was that it runs even if the runtime was already panicking. There aren't any changes to the macro which could have fixed this. I instead wrote my own function to check for a specific panicking closure. --- src/handle_unwind.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/handle_unwind.rs (limited to 'src/handle_unwind.rs') diff --git a/src/handle_unwind.rs b/src/handle_unwind.rs new file mode 100644 index 0000000..d515449 --- /dev/null +++ b/src/handle_unwind.rs @@ -0,0 +1,9 @@ +use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe}; + +pub fn handle_unwind R, G: FnOnce()>(try_fn: F, catch: G) -> R { + let try_fn = AssertUnwindSafe(try_fn); + catch_unwind(try_fn).unwrap_or_else(|e| { + catch(); + resume_unwind(e) + }) +} -- cgit v1.2.3