Some alternative designs that could provide even more information:
-
The allocator instance can report more information "out of band", e.g. keep information about few most recent allocation failures, and the OOM hook could query that information.
let lots_of_info = ALLOC.last_error(). Or the custom allocator could write failures directly to application's error log. -
The
Allocatortrait could have an associated type for allocator'sAllocErrortype, which could include more info. OOM panic payload could support downcasting to that custom error type. I imagine most allocators in release mode would keep that error as an empty unit type for performance, but they could switch to verbose errors in debug/testing builds.