Skip to main content

Crate pw_assert

Crate pw_assert 

Source
Expand description

§pw_assert

pw_assert provides crash-safe assert and panic macros that route to a central handler, pw_assert_HandleFailure. This is designed for embedded systems where standard library panics might not be suitable, or where specific logging/recovery behavior is needed.

The macros in this crate are designed to be drop-in replacements for core::panic!, core::assert!, etc., but they route through pw_log to log the failure before calling the crash handler.

§Example

#[unsafe(no_mangle)]
#[allow(non_snake_case)]
pub extern "C" fn pw_assert_HandleFailure() -> ! {
    pw_log::error!("Panicking!");
    loop {}
}
pw_assert::assert!(42 == 16, "Stack start is not aligned");

pw_assert::panic!("Unhandled interrupt: irq={}", 16 as u32);

pw_assert::debug_assert!(1 == 0);

pw_assert::debug_panic!("Next monotonic tick overflow");

Macros§

__private_log_panic_banner
assert
Asserts that a condition is true.
debug_assert
Asserts that a condition is true when debug_assertions are enabled.
debug_panic
Panics unconditionally when debug_assertions are enabled.
eq
Asserts that two expressions are equal (equivalent to assert_eq!).
ne
Asserts that two expressions are not equal (equivalent to assert_ne!).
panic
Panics unconditionally.

Functions§

pw_assert_HandleFailure
The crash handler called by asserts and panics when they fail.