Skip to content

Commit 39e1c28

Browse files
committed
Adding missing methods to Instant, matching Rust 1.39
1 parent 64c812a commit 39e1c28

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/wasm.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ impl Instant {
7070
pub fn elapsed(&self) -> Duration {
7171
Instant::now() - *self
7272
}
73+
74+
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> {
75+
match self.cmp(&earlier) {
76+
Ordering::Less => None,
77+
_ => Some(self.duration_since(earlier)),
78+
}
79+
}
80+
81+
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration {
82+
self.checked_duration_since(earlier).unwrap_or_default()
83+
}
84+
85+
pub fn checked_add(&self, duration: Duration) -> Option<Instant> {
86+
Some(*self + duration)
87+
}
88+
89+
pub fn checked_sub(&self, duration: Duration) -> Option<Instant> {
90+
Some(*self - duration)
91+
}
7392
}
7493

7594
impl Add<Duration> for Instant {

0 commit comments

Comments
 (0)