| Crates.io | run_once |
| lib.rs | run_once |
| version | 0.1.2 |
| created_at | 2025-02-10 08:07:38.459999+00 |
| updated_at | 2025-02-10 08:29:29.207962+00 |
| description | Runs code in rust once, from a closure |
| homepage | |
| repository | https://github.com/toastxc/run_once |
| max_upload_size | |
| id | 1549758 |
| size | 2,835 |
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);
}