pub struct Clock(/* private fields */);Expand description
An injectable source of “now”. Cloning is cheap and, for a test clock, shares the same controllable offset — so a handle handed to a test moves in lockstep with the clock the handler resolves.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn system() -> Clock
pub fn system() -> Clock
The real clock: now() reads SystemTime::now() each call. This is
what App::new() provides by default.
Sourcepub fn test() -> Clock
pub fn test() -> Clock
A controllable test clock. The base is SystemTime::now() at creation
— tests assert on movement (advance/set), not on an absolute base,
so a realistic starting instant is fine and avoids surprising callers
that subtract UNIX_EPOCH.
Sourcepub fn now(&self) -> SystemTime
pub fn now(&self) -> SystemTime
The current instant. For Clock::system this is the live system
clock; for Clock::test it is base + accumulated offset.
Sourcepub fn advance(&self, d: Duration)
pub fn advance(&self, d: Duration)
Move a test clock forward by d. Panics on a system clock — advancing
real time is meaningless, and silently ignoring it would hide a test bug.
Sourcepub fn set(&self, when: SystemTime)
pub fn set(&self, when: SystemTime)
Pin a test clock to an absolute instant. Panics on a system clock for
the same reason as advance. Useful for cron/expiry
tests that need a specific wall-clock time rather than a delta.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin for Clock
impl UnsafeUnpin for Clock
impl UnwindSafe for Clock
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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