How do I use a "BroadcastContext" to call spawn_broadcast with Rayon?

30 views Asked by At

I am new to Rust, and I am trying to understand the documentation for the Rayon library. I do not understand the prototype for or the definition of spawn_broadcast, and I also can't find an example of how to call this function. The manual reads:

source pub fn spawn_broadcast<OP>(&self, op: OP)
where
OP: Fn(BroadcastContext<'_>) + Send + Sync + 'static,

I don't know how to decipher this. I was able to figure out how to use spawn and spawn_fifo from looking at examples. Like this:

for i in 0..rayon::current_num_threads() {
  s.spawn(move |_s| {
    println!("Iteration {i}, thread {}",rayon::current_thread_index().unwrap());
  });
}

Does anyone know of an example of calling this method, or, can you explain what the definition means?

0

There are 0 answers