pub struct MockClock { /* private fields */ }Expand description
A deterministic clock backed by manually-advanced inner state.
Clone shares the same inner state — the same handle can be installed in a subsystem
(Arc<dyn Clock>) and held by the test (Arc<MockClock>) to advance time.
Implementations§
Source§impl MockClock
impl MockClock
Sourcepub fn advance(&self, dur: Duration)
pub fn advance(&self, dur: Duration)
Advance the clock by dur. All wakeups whose deadline is <= self.now() + dur resolve.
Sourcepub fn advance_secs(&self, secs: u64)
pub fn advance_secs(&self, secs: u64)
Advance the clock by secs seconds. Sugar for MockClock::advance.
Sourcepub fn advance_to_next_wakeup(&self) -> Option<Duration>
pub fn advance_to_next_wakeup(&self) -> Option<Duration>
Advance the clock to the deadline of the next pending wakeup, returning the elapsed
duration. Returns None when no wakeups are pending.
Sourcepub fn next_wakeup_in(&self) -> Option<Duration>
pub fn next_wakeup_in(&self) -> Option<Duration>
Peek at the duration until the next pending wakeup, without advancing the clock.
Returns None when no wakeups are pending.
Trait Implementations§
Source§impl Clock for MockClock
impl Clock for MockClock
Source§fn now(&self) -> Instant
fn now(&self) -> Instant
Monotonic timestamp suitable for measuring durations between two reads.
Source§fn delay(&self, dur: Duration) -> BoxedDelay
fn delay(&self, dur: Duration) -> BoxedDelay
Future that resolves after
dur has elapsed in this clock’s frame.Source§fn duration_since_epoch(&self) -> Duration
fn duration_since_epoch(&self) -> Duration
Wall-clock duration since the UNIX epoch. Used for slot math and persistence
timestamps; not monotonic. Callers pick a granularity (
as_secs, as_millis)
at the call site.Auto Trait Implementations§
impl Freeze for MockClock
impl RefUnwindSafe for MockClock
impl Send for MockClock
impl Sync for MockClock
impl Unpin for MockClock
impl UnwindSafe for MockClock
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
Mutably borrows from an owned value. Read more