Making caching support optional in Wasmtime (#2119)

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.
This commit is contained in:
Alex Crichton
2020-08-07 15:42:40 -05:00
committed by GitHub
parent a796d65467
commit 08f9eb1725
21 changed files with 104 additions and 54 deletions

View File

@@ -0,0 +1,29 @@
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)
}
}