run_once

Crates.iorun_once
lib.rsrun_once
version0.1.2
created_at2025-02-10 08:07:38.459999+00
updated_at2025-02-10 08:29:29.207962+00
descriptionRuns code in rust once, from a closure
homepage
repositoryhttps://github.com/toastxc/run_once
max_upload_size
id1549758
size2,835
ToastXC (toastxc)

documentation

README

Run Once

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, || {});

Example

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);
}
Commit count: 10

cargo fmt