Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use saturating_duration_since in elapsed instead of panicking #84344

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ impl Instant {

/// Returns the amount of time elapsed since this instant was created.
///
/// # Panics
///
/// This function may panic if the current time is earlier than this
/// Returns zero duration if the current time is earlier than this
/// instant, which is something that can happen if an `Instant` is
/// produced synthetically.
///
Expand All @@ -342,7 +340,7 @@ impl Instant {
/// ```
#[stable(feature = "time2", since = "1.8.0")]
pub fn elapsed(&self) -> Duration {
Instant::now() - *self
Instant::now().saturating_duration_since(*self)
}

/// Returns `Some(t)` where `t` is the time `self + duration` if `t` can be represented as
Expand Down