Skip to content

Commit 3aee2c2

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/wasm.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ 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+
let since = self.duration_since(earlier);
76+
if since >= 0 {
77+
return Some(Since);
78+
}
79+
None
80+
}
81+
82+
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration {
83+
self.checked_duration_since(earlier).unwrap_or_default()
84+
}
85+
86+
pub fn checked_add(&self, duration: Duration) -> Option<Instant> {
87+
Some(*self + duration)
88+
}
89+
90+
pub fn checked_sub(&self, duration: Duration) -> Option<Instant> {
91+
Some(*self - duration)
92+
}
7393
}
7494

7595
impl Add<Duration> for Instant {

0 commit comments

Comments
 (0)