Skip to main content

Clock

Trait Clock 

Source
pub trait Clock: Send + Sync {
    // Required method
    fn now(&self) -> Timestamp;

    // Provided methods
    fn advance_by(&self, _duration: Duration) { ... }
    fn set(&self, _timestamp: Timestamp) { ... }
}
Expand description

A source of virtual time.

Implementations must be shareable across threads (Send + Sync).

Required Methods§

Source

fn now(&self) -> Timestamp

The current virtual time.

Provided Methods§

Source

fn advance_by(&self, _duration: Duration)

Advances the clock by a duration.

The default implementation does nothing, for clocks whose time is externally controlled (such as the host wall clock). Virtual clocks override this to implement sleep and other time-advancing behavior.

Source

fn set(&self, _timestamp: Timestamp)

Sets the clock to an absolute point in virtual time.

The default implementation does nothing, for the same reason as Clock::advance_by.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§