pub struct FakeClock { /* private fields */ }Expand description
A fake clock that returns configurable timestamps.
This is useful for testing code that depends on timing without introducing non-determinism from real system clocks.
§Thread Safety
All methods are &self (not &mut self), making it safe
to share a single instance across multiple threads in tests.
§Example
use perfgate_fake::FakeClock;
use std::time::Duration;
let clock = FakeClock::new()
.with_millis(1000);
assert_eq!(clock.now_millis(), 1000);
clock.advance(Duration::from_millis(500));
assert_eq!(clock.now_millis(), 1500);Implementations§
Source§impl FakeClock
impl FakeClock
Sourcepub fn at_millis(millis: u64) -> Self
pub fn at_millis(millis: u64) -> Self
Create a FakeClock starting at a specific time in milliseconds.
Sourcepub fn with_millis(self, millis: u64) -> Self
pub fn with_millis(self, millis: u64) -> Self
Set the current time in milliseconds.
Sourcepub fn with_duration(self, duration: Duration) -> Self
pub fn with_duration(self, duration: Duration) -> Self
Set the current time.
Sourcepub fn now_millis(&self) -> u64
pub fn now_millis(&self) -> u64
Get the current time in milliseconds.
Sourcepub fn advance_millis(&self, millis: u64)
pub fn advance_millis(&self, millis: u64)
Advance the clock by a number of milliseconds.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FakeClock
impl RefUnwindSafe for FakeClock
impl Send for FakeClock
impl Sync for FakeClock
impl Unpin for FakeClock
impl UnsafeUnpin for FakeClock
impl UnwindSafe for FakeClock
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,
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