]> git.proxmox.com Git - rustc.git/blobdiff - src/libstd/sys/wasi/time.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / libstd / sys / wasi / time.rs
index 4394a22f9c233253cbcb8f8a323ecaeacf8b6f91..80ec317b5a2c60520fc03c634455b24b0cf3aed9 100644 (file)
@@ -1,5 +1,4 @@
 use crate::time::Duration;
-use ::wasi::wasi_unstable as wasi;
 
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
 pub struct Instant(Duration);
@@ -10,19 +9,18 @@ pub struct SystemTime(Duration);
 pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
 
 fn current_time(clock: u32) -> Duration {
-    let ts = wasi::clock_time_get(
-        clock,
-        1, // precision... seems ignored though?
-    ).unwrap();
-    Duration::new(
-        (ts / 1_000_000_000) as u64,
-        (ts % 1_000_000_000) as u32,
-    )
+    let ts = unsafe {
+        wasi::clock_time_get(
+            clock, 1, // precision... seems ignored though?
+        )
+        .unwrap()
+    };
+    Duration::new((ts / 1_000_000_000) as u64, (ts % 1_000_000_000) as u32)
 }
 
 impl Instant {
     pub fn now() -> Instant {
-        Instant(current_time(wasi::CLOCK_MONOTONIC))
+        Instant(current_time(wasi::CLOCKID_MONOTONIC))
     }
 
     pub const fn zero() -> Instant {
@@ -48,15 +46,14 @@ impl Instant {
 
 impl SystemTime {
     pub fn now() -> SystemTime {
-        SystemTime(current_time(wasi::CLOCK_REALTIME))
+        SystemTime(current_time(wasi::CLOCKID_REALTIME))
     }
 
     pub fn from_wasi_timestamp(ts: wasi::Timestamp) -> SystemTime {
         SystemTime(Duration::from_nanos(ts))
     }
 
-    pub fn sub_time(&self, other: &SystemTime)
-                    -> Result<Duration, Duration> {
+    pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
         self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0)
     }