When calling Rust code from C, it's unsafe to call panic!
. Doing so may
cause unsafe behavior. But when calling user-defined functions, we
sometimes need to enforce these rules.
To use this library, add the following to your Cargo.toml
file:
[dependencies]
abort_on_panic = "*"
You can than capture a panic!
as follows:
```rust
pub fn main() { let result = abortonpanic!({ "value" }); assert_eq!("value", result);
abort_on_panic!({
panic!("Uh oh.");
});
} ```
The original idea for this code came from Benjamin Herr. Many thanks!
This code is placed into the public domain under the terms described by the Unlicense.