pub struct Parallel<T: Send> { /* private fields */ }
Expand description
A cohesive set of thread-local values of a given type.
Mutable references can be fetched if T: Default
via Parallel::scope
.
Implementations§
Source§impl<T: Send> Parallel<T>
impl<T: Send> Parallel<T>
A scope guard of a Parallel
, when this struct is dropped ,the value will writeback to its Parallel
Source§impl<T: Default + Send> Parallel<T>
impl<T: Default + Send> Parallel<T>
Sourcepub fn scope<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
pub fn scope<R>(&self, f: impl FnOnce(&mut T) -> R) -> R
Retrieves the thread-local value for the current thread and runs f
on it.
If there is no thread-local value, it will be initialized to its default.
Sourcepub fn borrow_local_mut(&self) -> impl DerefMut<Target = T> + '_
pub fn borrow_local_mut(&self) -> impl DerefMut<Target = T> + '_
Mutably borrows the thread-local value.
If there is no thread-local value, it will be initialized to it’s default.
Source§impl<T, I> Parallel<I>
impl<T, I> Parallel<I>
Sourcepub fn drain<B>(&mut self) -> impl Iterator<Item = T> + '_where
B: FromIterator<T>,
pub fn drain<B>(&mut self) -> impl Iterator<Item = T> + '_where
B: FromIterator<T>,
Drains all enqueued items from all threads and returns an iterator over them.
Unlike Vec::drain
, this will piecemeal remove chunks of the data stored.
If iteration is terminated part way, the rest of the enqueued items in the same
chunk will be dropped, and the rest of the undrained elements will remain.
The ordering is not guaranteed.