[][src]Function checkers::with

pub fn with<F>(f: F) -> Snapshot where
    F: FnOnce(), 

Run the specified closure and return a snapshot of the memory state afterwards.

This can be useful to programmatically test for allocation invariants, while the default behavior is to simply panic on invariant errors.


static ALLOCATOR: checkers::Allocator = checkers::Allocator::system();

let snapshot = checkers::with(|| {
    let _ = vec![1, 2, 3, 4];

assert_eq!(2, snapshot.events.len());
assert!(snapshot.events[0].is_alloc_with(|a| a.size >= 16));
assert!(snapshot.events[1].is_free_with(|a| a.size >= 16));
assert_eq!(1, snapshot.events.allocs());
assert_eq!(1, snapshot.events.frees());
assert!(snapshot.events.max_memory_used().unwrap() >= 16);