Struct TimerHeap

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

Store timers in a binary heap. Keep them sorted by which timer is going to expire first.

Implementations§

Source§

impl<T: Eq + Clone + Hash> TimerHeap<T>

Source

pub fn new() -> TimerHeap<T>

Create a new TimerHeap

Source

pub fn len(&self) -> usize

Return the number of timers in the heap

Source

pub fn insert( &mut self, key: T, duration: Duration, ty: TimerType, ) -> Result<(), Error>

Insert a timer into the heap

Return an error if the key already exists.

Source

pub fn upsert(&mut self, key: T, duration: Duration, ty: TimerType) -> bool

Insert a timer into the heap, replacing any existing timer if one exists

Return true if a timer already existed in the heap, false otherwise

Source

pub fn remove(&mut self, key: T) -> bool

Remove a TimerEnry by Id

Return true if it exists, false otherwise

Source

pub fn time_remaining(&self) -> Option<Duration>

Return the amount of time remaining for the earliest expiring timer. Return None if there are no timers in the heap.

Source

pub fn earliest_timeout(&self, user_timeout: Duration) -> Duration

Return the earliest timeout based on a user timeout and the least remaining time in the next timer to fire.

Source

pub fn expired(&mut self) -> Expired<'_, T>

Return all expired keys

Any recurring timers will be re-added to the heap in the correct spot

Trait Implementations§

Source§

impl<T: Debug + Eq + Clone + Hash + Ord> Debug for TimerHeap<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TimerHeap<T>

§

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

§

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

§

impl<T> Sync for TimerHeap<T>
where T: Sync,

§

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

§

impl<T> UnwindSafe for TimerHeap<T>
where T: UnwindSafe,

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.