pub trait WaitClock {
// Required methods
fn elapsed(&self) -> Duration;
fn pause(&mut self, delay: Duration);
}Expand description
What:
The clock a lock wait reads and sleeps on:
how long the wait has lasted, and a pause between two attempts.
A trait is an interface a type implements.
Why:
A wait that reads the real clock prints as many notices as its polls happen to catch,
so a test of the notices would depend on how the operating system schedules the process.
A test hands the wait a clock that only moves when the wait pauses,
and the notices then follow from the cadence alone.
In TS you’d write (pseudocode):
interface WaitClock { elapsedMs(): number; pause(delayMs: number): void }Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".