This commit moves all of the caching support that currently lives in `wasmtime-environ` into a `wasmtime-cache` crate and makes it optional. The goal here is to slim down the `wasmtime-environ` crate and clearly separate boundaries where caching is a standalone and optional feature, not intertwined with other crates.
30 lines
744 B
Rust
30 lines
744 B
Rust
use lazy_static::lazy_static;
|
|
use std::time::{Duration, SystemTime, SystemTimeError};
|
|
|
|
lazy_static! {
|
|
pub static ref NOW: SystemTime = SystemTime::now(); // no need for RefCell and set_now() for 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)
|
|
}
|
|
}
|