Struct Cache

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

A simple caching struct that can be used to locally maintain a synchronized state with an actor

Implementations§

Source§

impl<T> Cache<T>
where T: Clone + Send + Sync + 'static,

Source

pub fn has_updates(&self) -> bool

Returns if any new updates are received

Source

pub fn get_newest(&mut self) -> &T

Returns the newest value available, even if the channel is closed Note that when the cache is initialized with a default value, this might return the default while the actor has a different value

Source

pub fn get_current(&self) -> &T

Returns the current value held by the cache, without synchronizing with the actor

Source

pub async fn recv_newest(&mut self) -> Result<&T, CacheRecvNewestError>

Receive the newest updated value broadcasted by the actor, discarding any older messages. The first time it will return its current value immediately After that, it might wait indefinitely for a new update Note that when the cache is initialized with a default value, this might return the default while the actor has a different value

Source

pub async fn recv(&mut self) -> Result<&T, CacheRecvError>

Receive the last updated value broadcasted by the actor (FIFO). The first time it will return its current value immediately After that, it might wait indefinitely for a new update Note that when the cache is initialized with a default value, this might return the default while the actor has a different value

Source

pub fn try_recv_newest(&mut self) -> Result<Option<&T>, CacheRecvNewestError>

Try to receive the newest updated value broadcasted by the actor, discarding any older messages. The first time it will return its initialized value, even if no updates are present. After that, lacking updates will return None. Note that when the cache is initialized with a default value, this might return None while the actor has a value

Source

pub fn try_recv(&mut self) -> Result<Option<&T>, CacheRecvError>

Try to receive the last updated value broadcasted by the actor once (FIFO). The first time it will return its initialized value, even if no updates are present. After that, lacking updates will return None. Note that when the cache is initialized with a default value, this might return None while the actor has a value

Source

pub fn spawn_throttle<C, F>(&self, client: C, call: fn(&C, F), freq: Frequency)
where C: Send + Sync + 'static, T: Throttled<F>, F: Clone + Send + Sync + 'static,

Spawns a throttle that fires given a specificed Frequency, given any broadcasted updates by the actor. Does not first update the cache to the newest value, since then the user of the cache might miss the update

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Cache<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<T> !RefUnwindSafe for Cache<T>

§

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

§

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

§

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

§

impl<T> !UnwindSafe for Cache<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Throttled<T> for T
where T: Clone,

Source§

fn parse(&self) -> T

Implement this parse function on the type to be sent by the throttle
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.