panic-custom 0.1.1

Small panicking rust crate that allows to easily set the behavior of panicking for embedded or regular no_std binaries.
Documentation
  • Coverage
  • 100%
    1 out of 1 items documented1 out of 1 items with examples
  • Size
  • Source code size: 23.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 594.12 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • not-forest/panic-custom
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • not-forest

Panic Custom

Small crate for custom panicking behavior, primarily designed for embedded or no_std projects.

By default, its behavior for panics is to halt in both release and debug mode. This crate, panic_custom, allows developers to customize this behavior by providing a custom panic handler function.

Usage

The crate provides two main ways to define custom panicking behavior:

  • Using the define_panic! macro with a closure argument.
  • Using the #[define_panic] procedural macro.

Using define_panic! Macro

The define_panic! macro allows you to define custom panicking behavior by passing a closure as an argument.

use panic_custom::define_panic;

const MY_CUSTOM_CONSTANT: usize = 0;

define_panic!(|info| {
    let a = &MY_CUSTOM_CONSTANT;
    let b = MY_CUSTOM_CONSTANT;

    42 // The return type is not important
});

Using #[define_panic] Procedural Macro

The #[define_panic] procedural macro allows you to define a custom panic handler function. To use this macro, enable the proc_macros feature and include features = "proc_macros" in your Cargo.toml.

[dependencies]
panic_custom = { version = "0.1", features = ["proc_macros"] }
use panic_custom::define_panic;
use core::panic::PanicInfo;

#[define_panic]
fn my_panic(info: &PanicInfo) -> ! {
    loop {}
}

Features

  • proc_macros: Enables procedural macros for custom panic handling.

  • abort_on_debug: Sets the default behavior to abort on panic in debug mode. By default, the crate halts on panic in debug mode.

  • abort_on_release: Sets the default behavior to abort on panic in release mode. By default, the crate halts on panic in release mode.