vce-engine 0.1.1

The generic state substrate of the Virtual Computing Engine (VCE)
Documentation
//! Virtual timestamps.
//!
//! Timestamps are produced by the Engine's [`Clock`](super::time::Clock). They
//! count nanoseconds since an arbitrary virtual epoch and have no relation to
//! the host wall clock unless the host clock implementation is used.

/// A point in virtual time, in nanoseconds since the virtual epoch.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Timestamp(u64);

impl Timestamp {
    /// The zero timestamp (the virtual epoch itself).
    pub const ZERO: Self = Self(0);

    /// Creates a timestamp from a raw nanosecond count.
    pub const fn from_nanos(nanos: u64) -> Self {
        Self(nanos)
    }

    /// Returns the raw nanosecond count.
    pub const fn as_nanos(self) -> u64 {
        self.0
    }
}

impl std::fmt::Display for Timestamp {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}ns", self.0)
    }
}