Rollup merge of #63053 - kornelski:clockdrift, r=shepmaster
SystemTime docs: recommend Instant for elapsed time Introduction to `SystemTime` mentions problems with non-monotonic clocks, but individual methods don't. For benefit of users who jump directly to method's documentation, also recommend `Instant` in `elapsed` and `duration_since`. `SystemTime::elapsed()` docs overpromised the elapsed time. It's not elapsed time, but a difference between two clocks.
This commit is contained in:
commit
117fa1de98
1 changed files with 8 additions and 2 deletions
|
@ -396,6 +396,7 @@ impl SystemTime {
|
||||||
/// This function may fail because measurements taken earlier are not
|
/// This function may fail because measurements taken earlier are not
|
||||||
/// guaranteed to always be before later measurements (due to anomalies such
|
/// guaranteed to always be before later measurements (due to anomalies such
|
||||||
/// as the system clock being adjusted either forwards or backwards).
|
/// as the system clock being adjusted either forwards or backwards).
|
||||||
|
/// [`Instant`] can be used to measure elapsed time without this risk of failure.
|
||||||
///
|
///
|
||||||
/// If successful, [`Ok`]`(`[`Duration`]`)` is returned where the duration represents
|
/// If successful, [`Ok`]`(`[`Duration`]`)` is returned where the duration represents
|
||||||
/// the amount of time elapsed from the specified measurement to this one.
|
/// the amount of time elapsed from the specified measurement to this one.
|
||||||
|
@ -406,6 +407,7 @@ impl SystemTime {
|
||||||
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
|
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
|
||||||
/// [`Duration`]: ../../std/time/struct.Duration.html
|
/// [`Duration`]: ../../std/time/struct.Duration.html
|
||||||
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
|
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
|
||||||
|
/// [`Instant`]: ../../std/time/struct.Instant.html
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -414,7 +416,7 @@ impl SystemTime {
|
||||||
///
|
///
|
||||||
/// let sys_time = SystemTime::now();
|
/// let sys_time = SystemTime::now();
|
||||||
/// let difference = sys_time.duration_since(sys_time)
|
/// let difference = sys_time.duration_since(sys_time)
|
||||||
/// .expect("SystemTime::duration_since failed");
|
/// .expect("Clock may have gone backwards");
|
||||||
/// println!("{:?}", difference);
|
/// println!("{:?}", difference);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "time2", since = "1.8.0")]
|
#[stable(feature = "time2", since = "1.8.0")]
|
||||||
|
@ -423,7 +425,8 @@ impl SystemTime {
|
||||||
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
|
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the amount of time elapsed since this system time was created.
|
/// Returns the difference between the clock time when this
|
||||||
|
/// system time was created, and the current clock time.
|
||||||
///
|
///
|
||||||
/// This function may fail as the underlying system clock is susceptible to
|
/// This function may fail as the underlying system clock is susceptible to
|
||||||
/// drift and updates (e.g., the system clock could go backwards), so this
|
/// drift and updates (e.g., the system clock could go backwards), so this
|
||||||
|
@ -431,12 +434,15 @@ impl SystemTime {
|
||||||
/// returned where the duration represents the amount of time elapsed from
|
/// returned where the duration represents the amount of time elapsed from
|
||||||
/// this time measurement to the current time.
|
/// this time measurement to the current time.
|
||||||
///
|
///
|
||||||
|
/// To measure elapsed time reliably, use [`Instant`] instead.
|
||||||
|
///
|
||||||
/// Returns an [`Err`] if `self` is later than the current system time, and
|
/// Returns an [`Err`] if `self` is later than the current system time, and
|
||||||
/// the error contains how far from the current system time `self` is.
|
/// the error contains how far from the current system time `self` is.
|
||||||
///
|
///
|
||||||
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
|
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
|
||||||
/// [`Duration`]: ../../std/time/struct.Duration.html
|
/// [`Duration`]: ../../std/time/struct.Duration.html
|
||||||
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
|
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
|
||||||
|
/// [`Instant`]: ../../std/time/struct.Instant.html
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue