Skip to content

Commit

Permalink
Fix checked_add/sub for sys/sgx/time.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Dec 11, 2018
1 parent 8111824 commit 442abbc
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/libstd/sys/sgx/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl Instant {
self.0 - other.0
}

pub fn add_duration(&self, other: &Duration) -> Instant {
Instant(self.0 + *other)
pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant(self.0.checked_add(*other)?))
}

pub fn sub_duration(&self, other: &Duration) -> Instant {
Instant(self.0 - *other)
pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant(self.0.checked_sub(*other)?))
}
}

Expand All @@ -47,15 +47,11 @@ impl SystemTime {
self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0)
}

pub fn add_duration(&self, other: &Duration) -> SystemTime {
SystemTime(self.0 + *other)
}

pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
self.0.checked_add(*other).map(|d| SystemTime(d))
Some(SystemTime(self.0.checked_add(*other)?))
}

pub fn sub_duration(&self, other: &Duration) -> SystemTime {
SystemTime(self.0 - *other)
pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
Some(SystemTime(self.0.checked_sub(*other)?))
}
}

0 comments on commit 442abbc

Please sign in to comment.