Crate alloc_fmt [−] [src]
Allocator-safe formatting and assertion macros.
alloc-fmt
provides formatting and assertion macros similar to the standard library's
println
, eprintln
, assert
, debug_assert
, etc which are safe for use in a global
allocator. The standard library's formatting and assertion macros can allocate, meaning that if
they are used in the implementation of a global allocator, it can cause infinite recursion. The
macros in this crate avoid this problem by either not allocating (in the case of formatting
macros) or detecting recursion (in the case of assertion macros).
Usage and Behavior
The macros in this crate are named alloc_xxx
, where xxx
is the name of the equivalent
standard library macro (e.g., alloc_println
, alloc_debug_assert
, etc).
The behavior of the formatting macros is identical to the behavior of their standard library counterparts. The behavior of the assertion macros is somewhat different. When an assertion fails, a message is first unconditionally printed to stderr (in case further processing causes a crash). A stack trace is then printed, and the process aborts. If recursion is detected during the printing of the stack trace, the process immediately aborts. Recusion can happen if, for example, the code that computes the stack trace allocates, triggering further assertion failures. This check is conservative - it may sometimes detect recursion when there is none.
Unlike the standard library assertion macros, no panic is generated, and once an assertion failure triggers, it cannot be caught or aborted.
Macros
alloc_assert | |
alloc_assert_eq | |
alloc_assert_ne | |
alloc_debug_assert | |
alloc_debug_assert_eq | |
alloc_debug_assert_ne | |
alloc_eprint | |
alloc_eprintln | |
alloc_print | |
alloc_println |