move more deps to cap-std-sync, define own SystemTimeSpec

This commit is contained in:
Pat Hickey
2021-01-21 12:35:55 -08:00
parent 61885b7071
commit fcd00f5de1
13 changed files with 160 additions and 167 deletions

View File

@@ -1,34 +1,20 @@
use cap_std::time::{Duration, Instant, MonotonicClock, SystemClock, SystemTime};
use cap_time_ext::{MonotonicClockExt, SystemClockExt};
use cap_std::time::{Duration, Instant, SystemTime};
pub enum SystemTimeSpec {
SymbolicNow,
Absolute(SystemTime),
}
pub trait WasiSystemClock {
fn resolution(&self) -> Duration;
fn now(&self, precision: Duration) -> SystemTime;
}
impl WasiSystemClock for SystemClock {
fn resolution(&self) -> Duration {
SystemClockExt::resolution(self)
}
fn now(&self, precision: Duration) -> SystemTime {
self.now_with(precision)
}
}
pub trait WasiMonotonicClock {
fn resolution(&self) -> Duration;
fn now(&self, precision: Duration) -> Instant;
}
impl WasiMonotonicClock for MonotonicClock {
fn resolution(&self) -> Duration {
MonotonicClockExt::resolution(self)
}
fn now(&self, precision: Duration) -> Instant {
self.now_with(precision)
}
}
pub struct WasiClocks {
pub system: Box<dyn WasiSystemClock>,
pub monotonic: Box<dyn WasiMonotonicClock>,