Function opt_out

Source
pub fn opt_out<F: FnOnce()>(run_while_not_counting: F)
Expand description

Opt out of counting allocations while running some code.

Useful to avoid certain parts of the code flow that should not be counted.

§Arguments

  • run_while_not_counting - The code to run while not counting allocations

§Examples

let info = allocation_counter::measure(|| {
    code_that_should_not_allocate();
    allocation_counter::opt_out(|| {
        external_code_that_should_not_be_tested();
    });
    code_that_should_not_allocate();
});
assert_eq!(info.count_total, 0);