[][src]Function alloc_counter::deny_alloc

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

Panic on any allocations during the provided closure. If code within the closure calls allow_alloc, allocations are allowed within that scope.

Examples:

// panics due to `Box` forcing a heap allocation
deny_alloc(|| Box::new(0));
fn foo(b: Box<i32>) {
    // safe since the drop happens in an `allow` closure
    deny_alloc(|| allow_alloc(|| drop(b)));
}
foo(Box::new(0));