Skip to main content

Clock

Trait Clock 

Source
pub trait Clock: Send + Sync {
    // Required methods
    fn now(&self) -> Duration;
    fn advance(&self, duration: Duration);

    // Provided method
    fn elapsed(&self, since: Duration) -> Duration { ... }
}
Expand description

Trait for monotonic time in protocol execution.

Time is measured as a monotonic offset from an arbitrary epoch. This trait is synchronous; async extensions are provided by downstream crates.

Required Methods§

Source

fn now(&self) -> Duration

Get the current monotonic offset.

Source

fn advance(&self, duration: Duration)

Advance simulated time by a duration.

For real clocks, this may be a no-op. For mock clocks, this immediately advances the internal counter.

Provided Methods§

Source

fn elapsed(&self, since: Duration) -> Duration

Get elapsed time since a previous monotonic point.

Implementors§