Struct Cache

Source
pub struct Cache<T> { /* private fields */ }
Expand description

This is a lock-free concurrent cache. It stores only the most up-to-date value.

Implementations§

Source§

impl<T> Cache<T>

Source

pub fn new(value: T, version: usize) -> Self

Source

pub fn value( &self, version: usize, f: impl FnOnce() -> T, ) -> Result<CacheValueType<T>, impl FnOnce() -> T>

Tries to retrieve value for the specified version. Returns a result either containing a cached value, or an f (which is guaranteed to be not invoked by function call in this case). If requested version corresponds to the value currently stored in cache - the value is returned. If requested version is older None will be returned. If requested version is newer, the new value will be computed and stored by calling f, and then returned, unless the value is being currently updated - in this case None will be returned. If None is returned it is guaranteed that f was not called.

Auto Trait Implementations§

§

impl<T> !Freeze for Cache<T>

§

impl<T> RefUnwindSafe for Cache<T>
where T: RefUnwindSafe,

§

impl<T> Send for Cache<T>
where T: Sync + Send,

§

impl<T> Sync for Cache<T>
where T: Sync + Send,

§

impl<T> Unpin for Cache<T>

§

impl<T> UnwindSafe for Cache<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.