Skip to content

Commit

Permalink
Clarify Duration::MAX depends on Instant
Browse files Browse the repository at this point in the history
Duration is used in std to represent a difference between two Instants.
As such, it has to at least contain that span of time in it. However,
Instant can vary by platform. Thus, we should explain the impl of
Duration::MAX is sensitive to these vagaries of the platform.
  • Loading branch information
workingjubilee committed Apr 24, 2021
1 parent 17234db commit a80dbea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ impl Duration {

/// The maximum duration.
///
/// It is roughly equal to a duration of 584,942,417,355 years.
/// May vary by platform. At least equal to the number of seconds
/// difference between the minimum and maximum [`std::time::Instant`].
/// On many platforms this is roughly 584,942,417,355 years.
///
/// # Examples
///
/// ```
/// #![feature(duration_constants)]
/// use std::time::Duration;
///
/// assert_eq!(Duration::MAX, Duration::new(u64::MAX, 1_000_000_000 - 1));
/// ```
/// [`std::time::Instant`]: ../../std/time/struct.Instant.html
#[stable(feature = "duration_saturating_ops", since = "1.53.0")]
pub const MAX: Duration = Duration::new(u64::MAX, NANOS_PER_SEC - 1);

Expand Down

0 comments on commit a80dbea

Please sign in to comment.