#panic #macro #proc-macro #panicking #custom

macro no-std panic-custom-proc-macros

Small panicking macro crate that allows to easily set the behavior of panicking for embedded or regular no_std binaries

1 unstable release

0.1.0 Mar 4, 2024

#20 in #custom


Used in panic-custom

MIT/Apache

6KB
68 lines

Small procedural macro crate for custom panic functions.

This crate provides a define_panic procedural macro, which transforms a given function into a panic handler. No closures are allowed with this macro.

Usage

To define a custom panic handler, annotate a function with #[panic_handler] macro. The function must adhere to the following signature: fn _some_name_(info: &PanicInfo) -> !.

Examples

use my_panic_macro::define_panic;

#[panic_handler]
fn my_panic_function(info: &PanicInfo) -> ! {
    // Custom panic handling logic
}

Limitations

  • This macro only accepts functions as input. Closures are not allowed.
  • The panic handler function must diverge, i.e., it must return !.
  • Ensure that the panic handler function is properly defined and handles panics safely to avoid undefined behavior.

See Also

Reference

Dependencies

~1.5MB
~37K SLoC