timed_map

Struct TimedMap

source
pub struct TimedMap<C, K, V>
where C: Clock, K: Eq + Copy,
{ /* private fields */ }
Expand description

Associates keys of type K with values of type V. Each entry may optionally expire after a specified duration.

Mutable functions automatically clears expired entries when called.

If no expiration is set, the entry remains constant.

Implementations§

source§

impl<C: Clock, K: Copy + Eq + Ord, V> TimedMap<C, K, V>

source

pub fn new() -> Self

Creates an empty map.

source

pub fn get(&self, k: &K) -> Option<&V>

Returns the associated value if present and not expired.

source

pub fn get_remaining_duration(&self, k: &K) -> Option<Duration>

Returns the associated value’s Duration if present and not expired.

Returns None if the entry does not exist or is constant.

source

pub fn insert_expirable(&mut self, k: K, v: V, duration: Duration) -> Option<V>

Inserts a key-value pair with an expiration duration.

If a value already exists for the given key, it will be updated and then the old one will be returned.

source

pub fn insert_constant(&mut self, k: K, v: V) -> Option<V>

Inserts a key-value pair with that doesn’t expire.

If a value already exists for the given key, it will be updated and then the old one will be returned.

source

pub fn remove(&mut self, k: &K) -> Option<V>

Removes a key-value pair from the map and returns the associated value if present and not expired.

Trait Implementations§

source§

impl<C: Clock, K: Copy + Eq + Ord, V> Default for TimedMap<C, K, V>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C, K, V> Freeze for TimedMap<C, K, V>

§

impl<C, K, V> RefUnwindSafe for TimedMap<C, K, V>

§

impl<C, K, V> Send for TimedMap<C, K, V>
where C: Send, K: Send, V: Send,

§

impl<C, K, V> Sync for TimedMap<C, K, V>
where C: Sync, K: Sync, V: Sync,

§

impl<C, K, V> Unpin for TimedMap<C, K, V>
where C: Unpin,

§

impl<C, K, V> UnwindSafe for TimedMap<C, K, V>

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.