Crate nounwind

Crate nounwind 

Source
Expand description

Defines a #[nounwind] attribute macro that prevents panics from unwinding, similar to the C++ noexcept specifier.

The panic_nounwind! macro offers a version of core::panic! that is guaranteed to abort instead of unwinding. This is useful for fatal errors which cannot possibly be recovered from. In particular, if proceeding could cause undefined behavior, panic_nounwind! should be used instead of core::panic!. Similar assert_nounwind! and unreachable_nounwind! macros are offered, which are convenience wrappers around panic_nounwind!.

The crate also provides a polyfill for the nightly std::panic::abort_unwind function. This provides more detailed control over what sections of code can and cannot panic. It can also be used as a replacement to #[nounwind] if you want to avoid a macro dependency.

Using #[nounwind] is clearer than using a drop guard, and in some versions of Rust can provide a better error message. In particular, on recent versions of rust using #[nounwind] will print a messages like “panic in a function that cannot unwind”.

Using panic_nounwind! is preferable to abort_unwind(|| panic!(..)), for reasons described in the abort_unwind docs.

§Feature Flags

The std feature provides superior error messages, so should be enabled wherever possible.

If the std feature cannot be enabled, and supporting versions of rust before 1.81 is needed, enable the old-rust-nostd feature. This will use libabort to provide a polyfill for std::process::abort.

Macros§

assert_nounwind
Equivalent to core::assert!, but guaranteed to abort the program instead of unwinding.
panic_nounwind
Equivalent to core::panic!, but guaranteed to abort the program instead of unwinding.
unreachable_nounwind
Equivalent to core::unreachable!, but guaranteed to abort the program instead of unwinding.

Functions§

abort_unwindnounwind_extern_c_will_abort
Invokes a closure, aborting if the closure unwinds.
panic_nounwind
Triggers a core::panic! with the specified message, but guaranteed to abort instead of unwinding.

Attribute Macros§

nounwindmacros
Indicates that a function should abort when panicking rather than unwinding.