[][src]Macro once::assert_has_not_been_called

macro_rules! assert_has_not_been_called {
    () => { ... };
    ($($arg:tt)+) => { ... };
}

This macro can be used to ensure that a function is called only once. It panics if the function is called a second time.

Example

Using the macro:

#[macro_use]
extern crate once;

fn init() {
    assert_has_not_been_called!();

    // code that should only run once
}

fn main() {
    init();
    // init(); // "assertion failed: called == false"
}

Custom error message:

#[macro_use]
extern crate once;

fn init() {
    assert_has_not_been_called!("the init function must only be called {}", "once");
}

fn main() {
    init();
    // init(); // "the init function must only be called once"
}