Skip to content

Commit

Permalink
Adding missing methods to Instant, matching Rust 1.39
Browse files Browse the repository at this point in the history
  • Loading branch information
fusetim committed Jul 11, 2021
1 parent 64c812a commit 39e1c28
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ impl Instant {
pub fn elapsed(&self) -> Duration {
Instant::now() - *self
}

pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> {
match self.cmp(&earlier) {
Ordering::Less => None,
_ => Some(self.duration_since(earlier)),
}
}

pub fn saturating_duration_since(&self, earlier: Instant) -> Duration {
self.checked_duration_since(earlier).unwrap_or_default()
}

pub fn checked_add(&self, duration: Duration) -> Option<Instant> {
Some(*self + duration)
}

pub fn checked_sub(&self, duration: Duration) -> Option<Instant> {
Some(*self - duration)
}
}

impl Add<Duration> for Instant {
Expand Down

0 comments on commit 39e1c28

Please sign in to comment.