}
}
+// NOTE(stage0): Remove impl after a snapshot
+#[cfg(stage0)]
impl Add<Duration, Timespec> for Timespec {
fn add(&self, other: &Duration) -> Timespec {
let d_sec = other.num_seconds();
}
}
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+impl Add<Duration, Timespec> for Timespec {
+ fn add(self, other: Duration) -> Timespec {
+ let d_sec = other.num_seconds();
+ // It is safe to unwrap the nanoseconds, because there cannot be
+ // more than one second left, which fits in i64 and in i32.
+ let d_nsec = (other - Duration::seconds(d_sec))
+ .num_nanoseconds().unwrap() as i32;
+ let mut sec = self.sec + d_sec;
+ let mut nsec = self.nsec + d_nsec;
+ if nsec >= NSEC_PER_SEC {
+ nsec -= NSEC_PER_SEC;
+ sec += 1;
+ } else if nsec < 0 {
+ nsec += NSEC_PER_SEC;
+ sec -= 1;
+ }
+ Timespec::new(sec, nsec)
+ }
+}
+
+// NOTE(stage0): Remove impl after a snapshot
+#[cfg(stage0)]
impl Sub<Timespec, Duration> for Timespec {
fn sub(&self, other: &Timespec) -> Duration {
let sec = self.sec - other.sec;
}
}
+#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
+impl Sub<Timespec, Duration> for Timespec {
+ fn sub(self, other: Timespec) -> Duration {
+ let sec = self.sec - other.sec;
+ let nsec = self.nsec - other.nsec;
+ Duration::seconds(sec) + Duration::nanoseconds(nsec as i64)
+ }
+}
+
/// Returns the current time as a `timespec` containing the seconds and
/// nanoseconds since 1970-01-01T00:00:00Z.
pub fn get_time() -> Timespec {