Allocator-safe formatting and assertion macros.
alloc-fmt provides formatting and assertion macros similar to the standard library's
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).
The macros in this crate are named
xxx is the name of the equivalent
standard library macro (e.g.,
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.