ManualClock

Struct ManualClock 

Source
pub struct ManualClock(/* private fields */);
Expand description

A clock whose reading is whatever the caller last set.

This is not a simulator and must not grow into one by accident: it does not advance itself, it has no notion of a pending timer, and nothing schedules against it. It exists so that a test can assert a program’s behaviour at a stated instant, and so that the seam has a second implementation — a seam with one implementation is an abstraction nobody has checked.

Implementations§

Source§

impl ManualClock

Source

pub fn at(millis: i64) -> ManualClock

Source

pub fn set(&self, millis: i64)

Source

pub fn advance(&self, millis: i64)

Move the clock forward. Panics on a negative step, because a wall clock that goes backwards is a bug in the test rather than a scenario worth supporting.

Trait Implementations§

Source§

impl Clock for ManualClock

Source§

fn now_millis(&self) -> i64

Milliseconds since the Unix epoch.
Source§

fn now_nanos(&self) -> u64

Nanoseconds since the Unix epoch — the unit OTLP asks for. Read more
Source§

impl Debug for ManualClock

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