pub struct FakeTimerCtx<Id> {
pub instant: FakeInstantCtx,
pub timers: BinaryHeap<InstantAndData<FakeTimer<Id>>>,
/* private fields */
}
Expand description
A fake TimerContext
which stores time as a FakeInstantCtx
.
Fields§
§instant: FakeInstantCtx
The instant context within this fake timer context.
timers: BinaryHeap<InstantAndData<FakeTimer<Id>>>
The timer heap kept by the fake implementation.
Implementations§
Source§impl<Id: Clone> FakeTimerCtx<Id>
impl<Id: Clone> FakeTimerCtx<Id>
Sourcepub fn timers(&self) -> Vec<(FakeInstant, Id)>
pub fn timers(&self) -> Vec<(FakeInstant, Id)>
Get an ordered list of all currently-scheduled timers.
Source§impl<Id: Debug + Clone + Hash + Eq> FakeTimerCtx<Id>
impl<Id: Debug + Clone + Hash + Eq> FakeTimerCtx<Id>
Sourcepub fn assert_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>(
&self,
timers: I,
)
pub fn assert_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>( &self, timers: I, )
Asserts that self
contains exactly the timers in timers
.
§Panics
Panics if timers
contains the same ID more than once or if self
does not contain exactly the timers in timers
.
Sourcepub fn assert_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>(
&self,
timers: I,
)
pub fn assert_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>( &self, timers: I, )
Like [assert_timers_installed
] but receives a range instants to
match.
Each timer must be present, and its deadline must fall into the specified range.
Sourcepub fn assert_some_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>(
&self,
timers: I,
)
pub fn assert_some_timers_installed<I: IntoIterator<Item = (Id, FakeInstant)>>( &self, timers: I, )
Asserts that self
contains at least the timers in timers
.
Like [assert_timers_installed
], but only asserts that timers
is
a subset of the timers installed; other timers may be installed in
addition to those in timers
.
Sourcepub fn assert_some_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>(
&self,
timers: I,
)
pub fn assert_some_timers_installed_range<R: RangeBounds<FakeInstant> + Debug, I: IntoIterator<Item = (Id, R)>>( &self, timers: I, )
Like [assert_some_timers_installed
] but receives instant ranges
to match like [assert_timers_installed_range
].
Sourcepub fn assert_no_timers_installed(&self)
pub fn assert_no_timers_installed(&self)
Trait Implementations§
Source§impl<Id> Default for FakeTimerCtx<Id>
impl<Id> Default for FakeTimerCtx<Id>
Source§fn default() -> FakeTimerCtx<Id>
fn default() -> FakeTimerCtx<Id>
Source§impl<Id> InstantBindingsTypes for FakeTimerCtx<Id>
impl<Id> InstantBindingsTypes for FakeTimerCtx<Id>
Source§type Instant = FakeInstant
type Instant = FakeInstant
Source§type AtomicInstant = FakeAtomicInstant
type AtomicInstant = FakeAtomicInstant
Self::Instant
.Source§impl<Id> InstantContext for FakeTimerCtx<Id>
impl<Id> InstantContext for FakeTimerCtx<Id>
Source§fn now(&self) -> FakeInstant
fn now(&self) -> FakeInstant
Source§fn now_atomic(&self) -> Self::AtomicInstant
fn now_atomic(&self) -> Self::AtomicInstant
Self::AtomicInstant
].Source§impl<Id: Debug + Clone + Send + Sync> TimerBindingsTypes for FakeTimerCtx<Id>
impl<Id: Debug + Clone + Send + Sync> TimerBindingsTypes for FakeTimerCtx<Id>
Source§type Timer = FakeTimer<Id>
type Timer = FakeTimer<Id>
TimerContext
.Source§type DispatchId = Id
type DispatchId = Id
Source§type UniqueTimerId = FakeTimerId
type UniqueTimerId = FakeTimerId
Timer
. It is given along with the
DispatchId
whenever a timer is fired. Read moreSource§impl<Id: PartialEq + Debug + Clone + Send + Sync> TimerContext for FakeTimerCtx<Id>
impl<Id: PartialEq + Debug + Clone + Send + Sync> TimerContext for FakeTimerCtx<Id>
Source§fn new_timer(&mut self, dispatch_id: Self::DispatchId) -> Self::Timer
fn new_timer(&mut self, dispatch_id: Self::DispatchId) -> Self::Timer
id
back to core when fired. Read moreSource§fn schedule_timer_instant(
&mut self,
time: Self::Instant,
timer: &mut Self::Timer,
) -> Option<Self::Instant>
fn schedule_timer_instant( &mut self, time: Self::Instant, timer: &mut Self::Timer, ) -> Option<Self::Instant>
Source§fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
Source§fn scheduled_instant(&self, timer: &mut Self::Timer) -> Option<Self::Instant>
fn scheduled_instant(&self, timer: &mut Self::Timer) -> Option<Self::Instant>
Source§fn unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId
fn unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId
timer
. Read moreSource§impl<TimerId> WithFakeTimerContext<TimerId> for FakeTimerCtx<TimerId>
impl<TimerId> WithFakeTimerContext<TimerId> for FakeTimerCtx<TimerId>
Source§fn with_fake_timer_ctx<O, F: FnOnce(&FakeTimerCtx<TimerId>) -> O>(
&self,
f: F,
) -> O
fn with_fake_timer_ctx<O, F: FnOnce(&FakeTimerCtx<TimerId>) -> O>( &self, f: F, ) -> O
FakeTimerCtx
.Source§fn with_fake_timer_ctx_mut<O, F: FnOnce(&mut FakeTimerCtx<TimerId>) -> O>(
&mut self,
f: F,
) -> O
fn with_fake_timer_ctx_mut<O, F: FnOnce(&mut FakeTimerCtx<TimerId>) -> O>( &mut self, f: F, ) -> O
FakeTimerCtx
.Auto Trait Implementations§
impl<Id> Freeze for FakeTimerCtx<Id>
impl<Id> RefUnwindSafe for FakeTimerCtx<Id>where
Id: RefUnwindSafe,
impl<Id> Send for FakeTimerCtx<Id>where
Id: Send,
impl<Id> Sync for FakeTimerCtx<Id>where
Id: Sync,
impl<Id> Unpin for FakeTimerCtx<Id>where
Id: Unpin,
impl<Id> UnwindSafe for FakeTimerCtx<Id>where
Id: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<O, BC> BuildableCoreContext<BC> for Owhere
O: Default,
impl<O, BC> BuildableCoreContext<BC> for Owhere
O: Default,
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<Id, Ctx> FakeTimerCtxExt<Id> for Ctx
impl<Id, Ctx> FakeTimerCtxExt<Id> for Ctx
Source§fn trigger_next_timer<H>(&mut self, handler: &mut H) -> Option<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_next_timer<H>(&mut self, handler: &mut H) -> Option<Id>where
H: TimerHandler<Ctx, Id>,
Triggers the next timer, if any, by calling f
on it.
trigger_next_timer
triggers the next timer, if any, advances the
internal clock to the timer’s scheduled time, and returns its ID.
Source§fn trigger_timers_until_instant<H>(
&mut self,
instant: FakeInstant,
handler: &mut H,
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_timers_until_instant<H>(
&mut self,
instant: FakeInstant,
handler: &mut H,
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
Skips the current time forward until instant
, triggering all timers
until then, inclusive, by giving them to handler
.
Returns the timers which were triggered.
§Panics
Panics if instant
is in the past.
Source§fn trigger_timers_for<H>(
&mut self,
duration: Duration,
handler: &mut H,
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
fn trigger_timers_for<H>(
&mut self,
duration: Duration,
handler: &mut H,
) -> Vec<Id>where
H: TimerHandler<Ctx, Id>,
Skips the current time forward by duration
, triggering all timers
until then, inclusive, by calling f
on them.
Returns the timers which were triggered.
Source§fn trigger_timers_and_expect_unordered<I, H>(
&mut self,
timers: I,
handler: &mut H,
)
fn trigger_timers_and_expect_unordered<I, H>( &mut self, timers: I, handler: &mut H, )
Triggers timers and expects them to be the given timers.
The number of timers to be triggered is taken to be the number of
timers produced by timers
. Timers may be triggered in any order.
§Panics
Panics under the following conditions:
- Fewer timers could be triggered than expected
- Timers were triggered that were not expected
- Timers that were expected were not triggered
Source§fn trigger_timers_until_and_expect_unordered<I, H>(
&mut self,
instant: FakeInstant,
timers: I,
handler: &mut H,
)
fn trigger_timers_until_and_expect_unordered<I, H>( &mut self, instant: FakeInstant, timers: I, handler: &mut H, )
Triggers timers until instant
and expects them to be the given
timers.
Like trigger_timers_and_expect_unordered
, except that timers will
only be triggered until instant
(inclusive).
Source§fn trigger_timers_for_and_expect<I, H>(
&mut self,
duration: Duration,
timers: I,
handler: &mut H,
)
fn trigger_timers_for_and_expect<I, H>( &mut self, duration: Duration, timers: I, handler: &mut H, )
Triggers timers for duration
and expects them to be the given
timers.
Like trigger_timers_and_expect_unordered
, except that timers will
only be triggered for duration
(inclusive).
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more