diff options
| author | Linus Färnstrand <faern@faern.net> | 2019-03-22 22:12:32 +0100 |
|---|---|---|
| committer | Linus Färnstrand <faern@faern.net> | 2019-03-22 22:53:07 +0100 |
| commit | d56b1fd0e7c09445574bae34332eeefa93713e44 (patch) | |
| tree | a7485fdc6f00af1605a92c781e3587c3a54db626 | |
| parent | 37cfeb271074ec31d65fef968edf24dd56b1e6aa (diff) | |
| download | rust-d56b1fd0e7c09445574bae34332eeefa93713e44.tar.gz rust-d56b1fd0e7c09445574bae34332eeefa93713e44.zip | |
Make duration_since use checked_duration_since
| -rw-r--r-- | src/libstd/time.rs | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 5abaac51da3..ab1a43d6672 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -212,7 +212,7 @@ impl Instant { /// ``` #[stable(feature = "time2", since = "1.8.0")] pub fn duration_since(&self, earlier: Instant) -> Duration { - self.0.sub_instant(&earlier.0) + self.0.checked_sub_instant(&earlier.0).expect("supplied instant is later than self") } /// Returns the amount of time elapsed from another instant to this one, @@ -233,11 +233,7 @@ impl Instant { /// ``` #[unstable(feature = "checked_duration_since", issue = "58402")] pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> { - if self >= &earlier { - Some(self.0.sub_instant(&earlier.0)) - } else { - None - } + self.0.checked_sub_instant(&earlier.0) } /// Returns the amount of time elapsed from another instant to this one, |
