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_manual() -> ClockController
pub fn install_manual() -> ClockController
Install a manual clock globally.
- If not initialized: installs manual clock, returns controller
- If already manual: returns existing controller (idempotent)
- If already realtime: panics
Must be called before any Clock::now() calls if you want manual time.
Sourcepub fn install_manual_at(start_at: DateTime<Utc>) -> ClockController
pub fn install_manual_at(start_at: DateTime<Utc>) -> ClockController
Install a manual clock globally starting at a specific time.
See install_manual for details.
Sourcepub fn manual_now() -> Option<DateTime<Utc>>
pub fn manual_now() -> Option<DateTime<Utc>>
Get the current manual time, if a manual clock is installed.
Returns:
Noneif no clock is initialized (doesn’t initialize one)Nonefor realtime clocksSome(time)for manual clocks
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
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