pub trait Fanout: Sync {
// Required methods
fn workers(&self) -> usize;
fn for_each<T, F>(&self, items: &mut [T], body: F)
where T: Send,
F: Fn(&mut T) + Send + Sync;
// Provided method
fn scope<R, F>(&self, work: F) -> R
where F: FnOnce() -> R + Send,
R: Send { ... }
}Expand description
A caller’s way of running independent work at the same time.
The simulation asks for one of these rather than depending on a scheduler, so the same step runs on a thread pool, on one thread, or on a host that has no threads at all.
§Examples
use concinnity_physics::{Fanout, Inline};
let mut work = [1u32, 2, 3];
Inline.for_each(&mut work, |item| *item *= 10);
assert_eq!(work, [10, 20, 30]);
assert_eq!(Inline.workers(), 1);Required Methods§
Sourcefn workers(&self) -> usize
fn workers(&self) -> usize
Units of work this fan-out can run at once. One means the work runs on the calling thread, which is what the simulation sizes its per-worker scratch against.
Provided Methods§
Sourcefn scope<R, F>(&self, work: F) -> R
fn scope<R, F>(&self, work: F) -> R
Run work with this fan-out’s workers already gathered, and return
what it produced.
Everything a step hands out happens inside one of these. An
implementation backed by a thread pool enters it here, so the
Fanout::for_each calls inside are already there; one with no pool
to enter leaves this as it is and runs work where it stands.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".