pub struct Cache<A: AtomicArcRef> { /* private fields */ }Expand description
A cache for a shared AtomicArc.
Built as a wrapper around AtomicArc::load_cached,
it essentially makes loads of up-to-date Arcs free, but requires a mutable reference.
As the cache stores the latest loaded Arc, it can delay its reclamation until a new Arc
is loaded.
§Examples
let atomic_arc = Arc::new(AtomicArc::<usize>::from(0));
let mut cache = hazarc::Cache::new(atomic_arc);
assert_eq!(**cache.load(), 0);It also works with AtomicOptionArc.
let atomic_arc = Arc::new(AtomicOptionArc::<usize>::none());
let mut cache = hazarc::Cache::new(atomic_arc);
assert_eq!(cache.load(), None);Implementations§
Source§impl<A: AtomicArcRef> Cache<A>
impl<A: AtomicArcRef> Cache<A>
Sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Consumes the cache to returns the inner shared AtomicArc.
Sourcepub fn load(&mut self) -> A::LoadCached<'_>
pub fn load(&mut self) -> A::LoadCached<'_>
Returns the cached Arc if it is up-to-date, or loads and caches the latest Arc.
Trait Implementations§
Source§impl<'de, A: AtomicArcRef + Deserialize<'de>> Deserialize<'de> for Cache<A>
Available on crate feature serde only.
impl<'de, A: AtomicArcRef + Deserialize<'de>> Deserialize<'de> for Cache<A>
Available on crate feature
serde only.Source§fn deserialize<De: Deserializer<'de>>(
deserializer: De,
) -> Result<Self, De::Error>
fn deserialize<De: Deserializer<'de>>( deserializer: De, ) -> Result<Self, De::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<A: AtomicArcRef> From<A> for Cache<A>
impl<A: AtomicArcRef> From<A> for Cache<A>
Auto Trait Implementations§
impl<A> Freeze for Cache<A>
impl<A> RefUnwindSafe for Cache<A>
impl<A> Send for Cache<A>
impl<A> Sync for Cache<A>
impl<A> Unpin for Cache<A>
impl<A> UnwindSafe for Cache<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more