[][src]Function alloc_counter::forbid_alloc

pub fn forbid_alloc<F, R>(f: F) -> R where
    F: FnOnce() -> R, 

Panic on any allocations during the provided closure, even if the closure contains code in an allow_alloc guard.

Example:

fn foo(b: Box<i32>) {
    // panics because of outer `forbid` even though drop happens in an allow closure
    forbid_alloc(|| allow_alloc(|| drop(b)))
}
foo(Box::new(0));