Function assert_infrequent::at_most [−][src]
pub fn at_most(n: usize)
Asserts that the given function is called at most n
times from any given point.
Example 1:
fn main() { assert_infrequent::at_most(1); // Ok, first call to at_most assert_infrequent::at_most(1); // Ok, first call to at_most at this callsite assert_infrequent::at_most(3); // Ok, 1 < 3. for _ in 0..5 { assert_infrequent::at_most(5); // Ok, only hit 5 times. } }
Example 2:
fn expensive_computation() -> u64 { assert_infrequent::at_most(1); // ... } fn main() { for _ in 0..2 { let v = expensive_computation(); // Panic! // ... } }