Skip to main content

MockClock

Struct MockClock 

Source
pub struct MockClock { /* private fields */ }
Available on crate feature mock only.
Expand description

A settable, advanceable clock for time-travel tests.

Implementations§

Source§

impl MockClock

Source

pub fn new(start: Timestamp) -> Self

A clock reading start until it is set or advanced.

Source

pub fn set_now(&self, instant: Timestamp)

Jump to instant and wake every pending sleep whose deadline it reaches.

Source

pub fn advance_by(&self, dur: Duration)

Move the clock forward by dur and wake every pending sleep whose deadline it reaches.

Source

pub fn advance_and_fire(&self, dur: Duration)

Advance time and fire all sleeps whose deadline has passed. Equivalent to tokio::time::advance for mock-aware code.

Trait Implementations§

Source§

impl Clock for MockClock

Source§

fn now(&self) -> Timestamp

The current instant. The one method an arm implements.
Source§

fn now_in(&self, tz: &TimeZone) -> Zoned

The current instant as a wall-clock reading in tz.
Source§

fn today_in(&self, tz: &TimeZone) -> Date

Today’s calendar date in tz — the date a person in that zone reads off their calendar, which differs from the UTC date near midnight.
Source§

fn now_unix_millis(&self) -> i64

The current instant as Unix epoch milliseconds.
Source§

impl Debug for MockClock

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.