Skip to main content

Clock

Trait Clock 

Source
pub trait Clock {
    type Reading: Copy;

    // Required method
    fn now(&self) -> Self::Reading;
}
Expand description

A clock: what time it is now.

The type a clock reads says which timeline its readings are on, so readings of two timelines never mix: a point for a clock that names a moment, and a span for one that counts CPU time.

§Examples

use core::cell::Cell;

use t2t_clock::Clock;
use t2t_core::Tickstamp;

/// A clock that moves one tick at each reading.
struct StepClock(Cell<i64>);

impl Clock for StepClock {
    type Reading = Tickstamp;

    fn now(&self) -> Tickstamp {
        self.0.set(self.0.get() + 1);
        Tickstamp::from_ticks(self.0.get())
    }
}

let clock = StepClock(Cell::new(0));
assert!(clock.now() < clock.now(), "each reading later than the last");

Required Associated Types§

Source

type Reading: Copy

What the clock reads.

Required Methods§

Source

fn now(&self) -> Self::Reading

The time now.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<C: Clock + ?Sized> Clock for &C

Source§

type Reading = <C as Clock>::Reading

Source§

fn now(&self) -> Self::Reading

Implementors§

Source§

impl Clock for BootClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for CoarseMonotonicClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for CoarseSystemClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for Counter

Source§

impl Clock for MonotonicClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for ProcessCpuClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for RawMonotonicClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for SystemClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for TaiClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl Clock for ThreadCpuClock

Available on 64-bit and crate feature std and (Linux or macOS) only.
Source§

impl<P: TimePoint> Clock for AtomicManualClock<P>

Source§

impl<P: TimePoint> Clock for ManualClock<P>