Macro define_panic_handler

Source
macro_rules! define_panic_handler {
    (loop) => { ... };
    (unreachable) => { ... };
    (web_api) => { ... };
    (web_api: $buffer_bytes:literal) => { ... };
    (custom, $func:path) => { ... };
}
Expand description

Defines a panic handler based on the chosen strategy.

  • loop: Enters an infinite loop, ensuring the program halts without undefined behavior.
  • unreachable: optimally halts execution based on the target architecture.
    • wasm32: Uses unreachable() to signal an unrecoverable state.
    • x86_64: Uses _mm_pause() to reduce CPU power consumption.
    • aarch64: Uses __nop() as a minimal halt.
    • riscv64: Uses wfi (wait-for-interrupt) to idle the core.
    • Fallback: Uses an infinite loop.
    • (It uses unsafe, except for wasm32 and the fallback.
  • web_api: Logs panic info to the Web console. It requires the js feature.
    • Accepts the size of the log buffer size in bytes. Defaults to 1024 bytes.
  • custom: Uses a user-provided function as the panic handler.