pub struct LocalTimerHeap<K, V, BT: TimerBindingsTypes + InstantBindingsTypes> { /* private fields */ }
Expand description

A local timer heap that keeps timers for core modules.

LocalTimerHeap manages its wakeups through a TimerContext.

K is the key that timers are keyed on. V is optional sidecar data to be kept with each timer.

Note that to provide fast timer deletion, LocalTimerHeap requires K to be Clone and the implementation assumes that the clone is cheap.

Implementations§

source§

impl<K, V, BC> LocalTimerHeap<K, V, BC>
where K: Hash + Eq + Clone + Debug, V: Debug + Eq + PartialEq, BC: TimerContext,

source

pub fn assert_timers( &self, timers: impl IntoIterator<Item = (K, V, BC::Instant)> )

Asserts installed timers with an iterator of (key, value, instant) tuples.

source

pub fn assert_timers_after( &self, bindings_ctx: &mut BC, timers: impl IntoIterator<Item = (K, V, Duration)> )

Like LocalTimerHeap::assert_timers, but asserts based on a duration after bindings_ctx.now().

source

pub fn assert_top(&mut self, key: &K, value: &V)

Assets that the next time to fire has key and value.

source

pub fn assert_range<'a, R: RangeBounds<BC::Instant> + Debug, I: IntoIterator<Item = (&'a K, R)>>( &'a self, expect: I )

Asserts that the given timer is installed with an instant at the provided range.

source§

impl<K, V, BC> LocalTimerHeap<K, V, BC>
where K: Hash + Eq + Clone, BC: TimerContext,

source

pub fn new(bindings_ctx: &mut BC, dispatch_id: BC::DispatchId) -> Self

Creates a new LocalTimerHeap with wakeup dispatch ID dispatch_id.

source

pub fn new_with_context<D, CC: CoreTimerContext<D, BC>>( bindings_ctx: &mut BC, dispatch_id: D ) -> Self

Like [new] but uses CC to covert the dispatch_id to match the type required by BC.

source

pub fn schedule_instant( &mut self, bindings_ctx: &mut BC, timer: K, value: V, at: BC::Instant ) -> Option<(BC::Instant, V)>

Schedules timer with value at or after at.

If timer was already scheduled, returns the previously scheduled instant and the associated value.

source

pub fn schedule_after( &mut self, bindings_ctx: &mut BC, timer: K, value: V, after: Duration ) -> Option<(BC::Instant, V)>

Like [schedule_instant] but does the instant math from current time.

§Panics

Panics if the current BC::Instant cannot be represented by adding duration after.

source

pub fn pop(&mut self, bindings_ctx: &mut BC) -> Option<(K, V)>

Pops an expired timer from the heap, if any.

source

pub fn get(&self, timer: &K) -> Option<(BC::Instant, &V)>

Returns the scheduled instant and associated value for timer, if it’s scheduled.

source

pub fn cancel( &mut self, bindings_ctx: &mut BC, timer: &K ) -> Option<(BC::Instant, V)>

Cancels timer, returning the scheduled instant and associated value if any.

source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V, &BC::Instant)>

Gets an iterator over the installed timers.

Trait Implementations§

source§

impl<K: Debug, V: Debug, BT: Debug + TimerBindingsTypes + InstantBindingsTypes> Debug for LocalTimerHeap<K, V, BT>
where BT::Timer: Debug, BT::Instant: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V, BT> Freeze for LocalTimerHeap<K, V, BT>

§

impl<K, V, BT> RefUnwindSafe for LocalTimerHeap<K, V, BT>

§

impl<K, V, BT> Send for LocalTimerHeap<K, V, BT>
where K: Send, V: Send,

§

impl<K, V, BT> Sync for LocalTimerHeap<K, V, BT>
where K: Sync, V: Sync,

§

impl<K, V, BT> Unpin for LocalTimerHeap<K, V, BT>

§

impl<K, V, BT> UnwindSafe for LocalTimerHeap<K, V, BT>

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<CC, BC, Meta> RecvFrameContext<BC, Meta> for CC
where Meta: ReceivableFrameMeta<CC, BC>,

source§

fn receive_frame<B>(&mut self, bindings_ctx: &mut BC, metadata: Meta, frame: B)
where B: BufferMut + Debug,

Receive a frame. Read more
source§

impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CC
where Meta: SendableFrameMeta<CC, BC>,

source§

fn send_frame<S>( &mut self, bindings_ctx: &mut BC, metadata: Meta, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Send a frame. Read more
source§

impl<Meta, BC> SendableFrameMeta<FakeFrameCtx<Meta>, BC> for Meta

source§

fn send_meta<S>( self, core_ctx: &mut FakeFrameCtx<Meta>, _bindings_ctx: &mut BC, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Sends this frame metadata to the provided contexts.
source§

impl<Id, CC, BC> TimerHandler<BC, Id> for CC
where Id: HandleableTimer<CC, BC>,

source§

fn handle_timer(&mut self, bindings_ctx: &mut BC, id: Id)

Handle a timer firing.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V