Skip to main content

Deadlines

Struct Deadlines 

Source
pub struct Deadlines<K> { /* private fields */ }
Expand description

A deadline heap keyed by K, holding at most one deadline per key.

next_timeout is O(1) and set/pop_expired are O(log n), so a host with many connections or requests never rescans them to arm its timer. Replaced deadlines stay in the heap until they surface and are discarded; the heap is rebuilt whenever they outnumber the live ones, so its size stays within a constant factor of len.

Implementations§

Source§

impl<K: Copy + Eq + Hash> Deadlines<K>

Source

pub fn new() -> Self

Source

pub fn set(&mut self, key: K, deadline: Option<Instant>)

Replace key’s deadline; None removes it.

Source

pub fn get(&self, key: K) -> Option<Instant>

Source

pub fn next_timeout(&self) -> Option<Instant>

The earliest live deadline.

Source

pub fn pop_expired(&mut self, now: Instant) -> Option<K>

Remove and return one key whose deadline is at or before now, earliest first. Call repeatedly until None.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl<K: Copy + Eq + Hash> Default for Deadlines<K>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K> Forget for Deadlines<K>

§

impl<K> Freeze for Deadlines<K>
where BinaryHeap<Reverse<Entry<K>>>: Freeze, HashMap<K, (Instant, u64)>: Freeze,

§

impl<K> RefUnwindSafe for Deadlines<K>

§

impl<K> Send for Deadlines<K>
where BinaryHeap<Reverse<Entry<K>>>: Send, HashMap<K, (Instant, u64)>: Send,

§

impl<K> Sync for Deadlines<K>
where BinaryHeap<Reverse<Entry<K>>>: Sync, HashMap<K, (Instant, u64)>: Sync,

§

impl<K> Unpin for Deadlines<K>
where BinaryHeap<Reverse<Entry<K>>>: Unpin, HashMap<K, (Instant, u64)>: Unpin,

§

impl<K> UnsafeUnpin for Deadlines<K>

§

impl<K> UnwindSafe for Deadlines<K>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.