pub fn assert_num_allocations<F: FnOnce()>(
    allowed_allocations: Range<u64>,
    run_while_counting: F
)
Expand description

Run a closure and assert that the number of memory allocations are inside a range.

Will only measure those done by the current thread, so take care when testing the memory allocations of multithreaded code.

Arguments

  • allowed_allocations - The range of allocations allowed
  • run_while_counting - The code to run while counting allocations

Examples

allocation_counter::assert_max_allocations(12, || {
    code_that_should_not_allocate_much();
});