[][src]Crate alloc_fmt

Allocator-safe formatting and assertion macros.

alloc-fmt provides formatting and assertion macros similar to the standard library's println, eprintln, panic, 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 panic and 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 panic and assertion macros is somewhat different. When an assertion fails or an explicit panic is invoked, 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 or panics. This check is conservative - it may sometimes detect recursion when there is none.

Unlike the standard library assertion and panic macros, the stack is not unwound, and once an assertion failure or panic 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_panic
alloc_print
alloc_println

Traits

AllocUnwrap

Types that can be unwrapped in an allocation-safe manner.