pub struct FixedClock { /* private fields */ }Expand description
Test clock with auto-advancing time.
This clock auto-advances on each now_millis() call, providing monotonically
increasing timestamps. Use hold() to temporarily freeze the clock for tests
needing stable timestamps.
Note: While timestamps are monotonic, concurrent threads may receive values in non-deterministic order depending on scheduling.
§Example
use eidetica::{Clock, FixedClock};
let clock = FixedClock::new(1000);
let t1 = clock.now_millis(); // Returns 1000, then advances
let t2 = clock.now_millis(); // Returns next value
assert!(t2 > t1);
// Use hold() for stable timestamps
{
let _hold = clock.hold();
let a = clock.now_millis();
let b = clock.now_millis();
assert_eq!(a, b); // Frozen
}Implementations§
Source§impl FixedClock
impl FixedClock
Sourcepub fn new(millis: u64) -> Self
pub fn new(millis: u64) -> Self
Create a new fixed clock with the given initial time in milliseconds.
Sourcepub fn hold(&self) -> ClockHold<'_>
pub fn hold(&self) -> ClockHold<'_>
Hold the clock, preventing auto-advance until the guard is dropped.
Returns an RAII guard that releases the hold when dropped. Use a scoped block for clean auto-release:
let clock = FixedClock::new(1000);
let expected = {
let _hold = clock.hold();
clock.now_millis() // Frozen value
}; // hold releasedTrait Implementations§
Source§impl Clock for FixedClock
Available on crate features testing only.
impl Clock for FixedClock
Available on crate features
testing only.Source§impl Clone for FixedClock
Available on crate features testing only.
impl Clone for FixedClock
Available on crate features
testing only.Source§impl Debug for FixedClock
Available on crate features testing only.
impl Debug for FixedClock
Available on crate features
testing only.Auto Trait Implementations§
impl !Freeze for FixedClock
impl RefUnwindSafe for FixedClock
impl Send for FixedClock
impl Sync for FixedClock
impl Unpin for FixedClock
impl UnwindSafe for FixedClock
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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