//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
//! depending on the value of cfg!(parallel_compiler).
+use crate::owning_ref::{Erased, OwningRef};
use std::collections::HashMap;
-use std::hash::{Hash, BuildHasher};
+use std::hash::{BuildHasher, Hash};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
-use crate::owning_ref::{Erased, OwningRef};
-pub use std::sync::atomic::Ordering::SeqCst;
pub use std::sync::atomic::Ordering;
+pub use std::sync::atomic::Ordering::SeqCst;
cfg_if! {
if #[cfg(not(parallel_compiler))] {
t.into_iter()
}
- pub fn par_for_each_in<T: IntoIterator>(
- t: T,
- for_each:
- impl Fn(<<T as IntoIterator>::IntoIter as Iterator>::Item) + Sync + Send
- ) {
+ pub fn par_for_each_in<T: IntoIterator>(t: T, for_each: impl Fn(T::Item) + Sync + Send) {
// We catch panics here ensuring that all the loop iterations execute.
// This makes behavior consistent with the parallel compiler.
let mut panic = None;
pub fn par_for_each_in<T: IntoParallelIterator>(
t: T,
- for_each: impl Fn(
- <<T as IntoParallelIterator>::Iter as ParallelIterator>::Item
- ) + Sync + Send
+ for_each: impl Fn(T::Item) + Sync + Send,
) {
t.into_par_iter().for_each(for_each)
}
/// otherwise if the inner value was already set it asserts that `value` is equal to the inner
/// value and then returns `value` back to the caller
#[inline]
- pub fn try_set_same(&self, value: T) -> Option<T> where T: Eq {
+ pub fn try_set_same(&self, value: T) -> Option<T>
+ where
+ T: Eq,
+ {
let mut lock = self.0.lock();
if let Some(ref inner) = *lock {
assert!(*inner == value);
assert!(self.try_set(value).is_none());
}
- /// Tries to initialize the inner value by calling the closure while ensuring that no-one else
- /// can access the value in the mean time by holding a lock for the duration of the closure.
- /// If the value was already initialized the closure is not called and `false` is returned,
- /// otherwise if the value from the closure initializes the inner value, `true` is returned
+ /// Initializes the inner value if it wasn't already done by calling the provided closure. It
+ /// ensures that no-one else can access the value in the mean time by holding a lock for the
+ /// duration of the closure.
+ /// A reference to the inner value is returned.
#[inline]
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
{
/// If the value is already initialized, the closure is not called and `None` is returned.
#[inline]
pub fn init_nonlocking<F: FnOnce() -> T>(&self, f: F) -> Option<T> {
- if self.0.lock().is_some() {
- None
- } else {
- self.try_set(f())
- }
+ if self.0.lock().is_some() { None } else { self.try_set(f()) }
}
/// Tries to initialize the inner value by calling the closure without ensuring that no-one
/// If our closure set the value, `None` is returned.
/// If the value is already initialized, the closure is not called and `None` is returned.
#[inline]
- pub fn init_nonlocking_same<F: FnOnce() -> T>(&self, f: F) -> Option<T> where T: Eq {
- if self.0.lock().is_some() {
- None
- } else {
- self.try_set_same(f())
- }
+ pub fn init_nonlocking_same<F: FnOnce() -> T>(&self, f: F) -> Option<T>
+ where
+ T: Eq,
+ {
+ if self.0.lock().is_some() { None } else { self.try_set_same(f()) }
}
/// Tries to get a reference to the inner value, returns `None` if it is not yet initialized