Skip to main content

ManualClock

Struct ManualClock 

Source
pub struct ManualClock { /* private fields */ }
Expand description

A clock that only moves when a test moves it.

use chrono::{TimeDelta, Utc};
use turnframe_store::memory::{Clock, ManualClock};

let clock = ManualClock::new(Utc::now());
let start = clock.now();
clock.advance(TimeDelta::seconds(30));
assert_eq!(clock.now(), start + TimeDelta::seconds(30));

Implementations§

Source§

impl ManualClock

Source

pub fn new(start: DateTime<Utc>) -> Self

A clock stopped at start.

Source

pub fn epoch() -> Self

A clock stopped at the Unix epoch, for tests that only care about order.

Source

pub fn set(&self, instant: DateTime<Utc>)

Moves the clock to instant, forwards or backwards.

A poisoned lock is ignored: the clock is a test fixture and losing its value cannot corrupt anything a store relies on.

Source

pub fn advance(&self, delta: TimeDelta)

Moves the clock forward by delta.

Trait Implementations§

Source§

impl Clock for ManualClock

Source§

fn now(&self) -> DateTime<Utc>

The current instant, in UTC.
Source§

impl Debug for ManualClock

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ManualClock

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.