[][src]Function alloc_counter::allow_alloc

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

Allow allocations for a closure, even if running in a deny closure. Allocations during a forbid closure will still cause a panic.

Examples:

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