std-type

AssertUnwindSafe — explicit boundary assertion

This wrapper asserts a value or closure meets the relevant unwind-safety expectation. Use only after reviewing the state that might be observed following a panic; it does not roll back modifications. Prefer narrow assertions over wrapping an entire closure indiscriminately. Expected stdout (not executed): true 1 Common mistake: Using the wrapper just to silence a compiler error without reasoning about state.

Formal Syntax & Structure

rust syntaxrust
pub struct AssertUnwindSafe<T>(pub T);

Working Example

Example Snippetrust
fn main() {    let mut count = 0;    let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { count += 1; panic!("after update"); }));    println!("{} {count}", result.is_err());}
Rust Reference