Skip to main content

TtlMap

Struct TtlMap 

Source
pub struct TtlMap<K, V>
where K: Eq + Hash,
{ /* private fields */ }
Expand description

A HashMap whose entries expire after ttl.

Implementations§

Source§

impl<K, V> TtlMap<K, V>
where K: Eq + Hash + Clone,

Source

pub fn new(ttl: Duration) -> Self

Creates a new map with the given TTL.

A ttl of zero disables expiry entirely — entries stay until explicitly removed.

Source

pub fn with_on_expire<F>(self, cb: F) -> Self
where F: Fn(&K, V) + Send + Sync + 'static,

Sets a callback invoked whenever an entry is removed due to TTL expiry.

The registry uses this to reject pending request promises with a timeout error.

Source

pub fn insert(&self, key: K, value: V) -> Option<V>

Inserts a value, returning the previous entry if any.

Source

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

Removes and returns the value for key, bypassing expiry.

Source

pub fn contains_key(&self, key: &K) -> bool

Returns whether key is present and unexpired.

Triggers on_expire as a side effect if the entry is stale.

Source

pub fn get_cloned(&self, key: &K) -> Option<V>
where V: Clone,

Returns a clone of the value for key if present and unexpired.

Source

pub fn len(&self) -> usize

Returns the current size of the map (including any stale entries that have not yet been touched).

Source

pub fn is_empty(&self) -> bool

Source

pub fn clear(&self)

Drops all entries without firing on_expire.

Source

pub fn sweep_expired(&self)

Removes every entry that has exceeded the TTL, firing on_expire for each. Callers may invoke this periodically to bound memory in long-running processes.

Source

pub fn snapshot_keys_where<F>(&self, pred: F) -> Vec<K>
where F: Fn(&V) -> bool,

Returns every key whose (unexpired) value satisfies pred.

The registry uses this during channel-close cleanup to find all pending replies and routes associated with the dead channel.

Auto Trait Implementations§

§

impl<K, V> !Freeze for TtlMap<K, V>

§

impl<K, V> !RefUnwindSafe for TtlMap<K, V>

§

impl<K, V> Send for TtlMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for TtlMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Unpin for TtlMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for TtlMap<K, V>

§

impl<K, V> !UnwindSafe for TtlMap<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.