Sha256: ee47f898209772a1183dae618f3f0956c76cd10cb67f260b81d01674a25e9faa

Contents?: true

Size: 1.62 KB

Versions: 34

Compression:

Stored size: 1.62 KB

Contents

use crate::time::{Duration, SystemTime, SystemTimeError};
use ambient_authority::AmbientAuthority;
use std::time;

/// A reference to a system clock, useful for talking to external entities like
/// the file system or other processes.
///
/// This does not directly correspond to anything in `std`, however its methods
/// correspond to [methods in `std::time::SystemTime`].
///
/// [methods in `std::time::SystemTime`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#impl
pub struct SystemClock(());

impl SystemClock {
    /// An anchor in time which can be used to create new `SystemTime`
    /// instances or learn about where in time a `SystemTime` lies.
    ///
    /// This corresponds to [`std::time::SystemTime::UNIX_EPOCH`].
    pub const UNIX_EPOCH: SystemTime = SystemTime {
        std: time::SystemTime::UNIX_EPOCH,
    };

    /// Constructs a new instance of `Self`.
    ///
    /// # Ambient Authority
    ///
    /// This uses ambient authority to accesses clocks.
    #[inline]
    pub const fn new(ambient_authority: AmbientAuthority) -> Self {
        let _ = ambient_authority;
        Self(())
    }

    /// Returns an instant corresponding to "now".
    ///
    /// This corresponds to [`std::time::SystemTime::now`].
    #[inline]
    pub fn now(&self) -> SystemTime {
        SystemTime::from_std(time::SystemTime::now())
    }

    /// Returns the amount of time elapsed since this instant was created.
    ///
    /// This corresponds to [`std::time::SystemTime::elapsed`].
    #[inline]
    pub fn elapsed(&self, system_time: SystemTime) -> Result<Duration, SystemTimeError> {
        system_time.std.elapsed()
    }
}

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/cap-primitives-3.4.2/src/time/system_clock.rs
wasmtime-29.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/time/system_clock.rs
wasmtime-28.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/time/system_clock.rs
wasmtime-27.0.0 ./ext/cargo-vendor/cap-primitives-3.4.1/src/time/system_clock.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cap-primitives-3.3.0/src/time/system_clock.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cap-primitives-3.2.0/src/time/system_clock.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cap-primitives-3.2.0/src/time/system_clock.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/time/system_clock.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/time/system_clock.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/time/system_clock.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cap-primitives-3.1.0/src/time/system_clock.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cap-primitives-3.1.0/src/time/system_clock.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/time/system_clock.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cap-primitives-3.0.0/src/time/system_clock.rs
wasmtime-18.0.3 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/time/system_clock.rs