usesuper::{IntoIter, IterMut, ThreadLocal}; use std::fmt; use std::panic::UnwindSafe; use std::usize;
/// Wrapper around [`ThreadLocal`]. /// /// This used to add a fast path for a single thread, however that has been /// obsoleted by performance improvements to [`ThreadLocal`] itself. #[deprecated(since = "1.1.0", note = "Use `ThreadLocal` instead")] pubstruct CachedThreadLocal<T: Send> {
inner: ThreadLocal<T>,
}
/// Returns the element for the current thread, if it exists. #[inline] pubfn get(&self) -> Option<&T> { self.inner.get()
}
/// Returns the element for the current thread, or creates it if it doesn't /// exist. #[inline] pubfn get_or<F>(&self, create: F) -> &T where
F: FnOnce() -> T,
{ self.inner.get_or(create)
}
/// Returns the element for the current thread, or creates it if it doesn't /// exist. If `create` fails, that error is returned and no element is /// added. #[inline] pubfn get_or_try<F, E>(&self, create: F) -> Result<&T, E> where
F: FnOnce() -> Result<T, E>,
{ self.inner.get_or_try(create)
}
/// Returns a mutable iterator over the local values of all threads. /// /// Since this call borrows the `ThreadLocal` mutably, this operation can /// be done safely---the mutable borrow statically guarantees no other /// threads are currently accessing their associated values. #[inline] pubfn iter_mut(&mutself) -> CachedIterMut<T> {
CachedIterMut {
inner: self.inner.iter_mut(),
}
}
/// Removes all thread-specific values from the `ThreadLocal`, effectively /// reseting it to its original state. /// /// Since this call borrows the `ThreadLocal` mutably, this operation can /// be done safely---the mutable borrow statically guarantees no other /// threads are currently accessing their associated values. #[inline] pubfn clear(&mutself) { self.inner.clear();
}
}
impl<T: Send> IntoIterator for CachedThreadLocal<T> { type Item = T; type IntoIter = CachedIntoIter<T>;
impl<T: Send + Default> CachedThreadLocal<T> { /// Returns the element for the current thread, or creates a default one if /// it doesn't exist. pubfn get_or_default(&self) -> &T { self.get_or(T::default)
}
}
impl<'a, T: Send + 'a> ExactSizeIterator for CachedIterMut<'a, T> {}
/// An iterator that moves out of a `CachedThreadLocal`. #[deprecated(since = "1.1.0", note = "Use `IntoIter` instead")] pubstruct CachedIntoIter<T: Send> {
inner: IntoIter<T>,
}
impl<T: Send> Iterator for CachedIntoIter<T> { type Item = T;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.