Skip to main content

Clock

Trait Clock 

Source
pub trait Clock:
    Send
    + Sync
    + Debug {
    // Required methods
    fn elapsed(&self) -> Duration;
    fn sleep(
        &self,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>;
    fn unix_now(&self) -> Duration;

    // Provided method
    fn today_utc(&self) -> Result<CalendarDate, Error> { ... }
}
Expand description

The clock a refresh boundary is measured on. It’s the crate’s one Clock, and the production one is tokio’s (TokioClock, in microvms-edges): a token timed on std::time::Instant would never re-mint inside a simulation. Time, injectable so a wait or a refresh boundary is a test rather than a wait.

Required Methods§

Source

fn elapsed(&self) -> Duration

Monotonic time since this clock was created. Never decreases.

Source

fn sleep( &self, duration: Duration, ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>

Sleeps for duration.

Source

fn unix_now(&self) -> Duration

Wall time since the Unix epoch.

Zero if the host clock is set before 1970, which is a machine whose dates are already meaningless; a reading that can’t be negative is what every caller wants.

Provided Methods§

Source

fn today_utc(&self) -> Result<CalendarDate, Error>

Today, UTC, for the cost engine’s dates.

Fails only for a wall reading past 9999-12-31, the last date the domain represents.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§