Sha256: 17c1651e1a1dbb3cad353449ebe8e64f509a7b21ecea37b7284bb29f9a4284e9

Contents?: true

Size: 692 Bytes

Versions: 4

Compression:

Stored size: 692 Bytes

Contents

use std::sync::LazyLock;
use std::time::{Duration, SystemTime, SystemTimeError};

pub static NOW: LazyLock<SystemTime> = LazyLock::new(SystemTime::now);

#[derive(PartialOrd, PartialEq, Ord, Eq)]
pub struct SystemTimeStub(SystemTime);

impl SystemTimeStub {
    pub fn now() -> Self {
        Self(*NOW)
    }

    pub fn checked_add(&self, duration: Duration) -> Option<Self> {
        self.0.checked_add(duration).map(|t| t.into())
    }

    pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
        self.0.duration_since(earlier)
    }
}

impl From<SystemTime> for SystemTimeStub {
    fn from(time: SystemTime) -> Self {
        Self(time)
    }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/wasmtime-cache-30.0.2/src/worker/tests/system_time_stub.rs
wasmtime-29.0.0 ./ext/cargo-vendor/wasmtime-cache-29.0.0/src/worker/tests/system_time_stub.rs
wasmtime-28.0.0 ./ext/cargo-vendor/wasmtime-cache-28.0.0/src/worker/tests/system_time_stub.rs
wasmtime-27.0.0 ./ext/cargo-vendor/wasmtime-cache-27.0.0/src/worker/tests/system_time_stub.rs