pub struct Clock;Expand description
Global clock access - like Utc::now() but testable.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn now() -> DateTime<Utc>
pub fn now() -> DateTime<Utc>
Get current time from the global clock.
Lazily initializes to realtime if not already set.
Sourcepub fn today() -> NaiveDate
pub fn today() -> NaiveDate
Get the current date (without time component).
Lazily initializes to realtime if not already set.
Sourcepub fn sleep(duration: Duration) -> ClockSleep ⓘ
pub fn sleep(duration: Duration) -> ClockSleep ⓘ
Sleep using the global clock.
Sourcepub fn timeout<F: Future>(duration: Duration, future: F) -> ClockTimeout<F> ⓘ
pub fn timeout<F: Future>(duration: Duration, future: F) -> ClockTimeout<F> ⓘ
Timeout using the global clock.
Sourcepub fn handle() -> &'static ClockHandle
pub fn handle() -> &'static ClockHandle
Get a reference to the global clock handle.
Sourcepub fn install_artificial(config: ArtificialClockConfig) -> ClockController
pub fn install_artificial(config: ArtificialClockConfig) -> ClockController
Install an artificial clock globally.
- If not initialized: installs artificial clock, returns controller
- If already artificial: returns existing controller (idempotent)
- If already realtime: panics
Must be called before any Clock::now() calls if you want artificial time.
Sourcepub fn is_artificial() -> bool
pub fn is_artificial() -> bool
Check if an artificial clock is installed.
Sourcepub fn artificial_now() -> Option<DateTime<Utc>>
pub fn artificial_now() -> Option<DateTime<Utc>>
Get the current artificial time, if an artificial clock is installed and hasn’t transitioned to realtime.
Returns:
Noneif no clock is initialized (doesn’t initialize one)Nonefor realtime clocksNonefor artificial clocks that have transitioned to realtimeSome(time)for artificial clocks that are still artificial
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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