Run Once
Code inside the closure (of the same value*) will only run once.
r.run_once;
Two closures of different values will both run once.
r.run_once;
r.run_once;
Example
Code inside the closure (of the same value*) will only run once.
r.run_once(1, || {
// do stuff here!
});
Two closures of different values will both run once.
r.run_once(1, || {});
r.run_once(2, || {});
fn test() {
let mut data = RunOnce::default();
let mut value = 0;
for _ in 0..5 {
data.run_once(1, || {
value += 1;
});
}
assert_eq!(value, 1);
}