@@ -396,6 +396,7 @@ impl SystemTime {
396
396
/// This function may fail because measurements taken earlier are not
397
397
/// guaranteed to always be before later measurements (due to anomalies such
398
398
/// as the system clock being adjusted either forwards or backwards).
399
+ /// [`Instant`] can be used to measure elapsed time without this risk of failure.
399
400
///
400
401
/// If successful, [`Ok`]`(`[`Duration`]`)` is returned where the duration represents
401
402
/// the amount of time elapsed from the specified measurement to this one.
@@ -406,6 +407,7 @@ impl SystemTime {
406
407
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
407
408
/// [`Duration`]: ../../std/time/struct.Duration.html
408
409
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
410
+ /// [`Instant`]: ../../std/time/struct.Instant.html
409
411
///
410
412
/// # Examples
411
413
///
@@ -414,7 +416,7 @@ impl SystemTime {
414
416
///
415
417
/// let sys_time = SystemTime::now();
416
418
/// let difference = sys_time.duration_since(sys_time)
417
- /// .expect("SystemTime::duration_since failed ");
419
+ /// .expect("Clock may have went backwards ");
418
420
/// println!("{:?}", difference);
419
421
/// ```
420
422
#[ stable( feature = "time2" , since = "1.8.0" ) ]
@@ -423,20 +425,24 @@ impl SystemTime {
423
425
self . 0 . sub_time ( & earlier. 0 ) . map_err ( SystemTimeError )
424
426
}
425
427
426
- /// Returns the amount of time elapsed since this system time was created.
428
+ /// Returns the difference between the clock time when this
429
+ /// system time was created, and the current clock time.
427
430
///
428
431
/// This function may fail as the underlying system clock is susceptible to
429
432
/// drift and updates (e.g., the system clock could go backwards), so this
430
433
/// function may not always succeed. If successful, [`Ok`]`(`[`Duration`]`)` is
431
434
/// returned where the duration represents the amount of time elapsed from
432
435
/// this time measurement to the current time.
433
436
///
437
+ /// To measure elapsed time reliably, use [`Instant`] instead.
438
+ ///
434
439
/// Returns an [`Err`] if `self` is later than the current system time, and
435
440
/// the error contains how far from the current system time `self` is.
436
441
///
437
442
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
438
443
/// [`Duration`]: ../../std/time/struct.Duration.html
439
444
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
445
+ /// [`Instant`]: ../../std/time/struct.Instant.html
440
446
///
441
447
/// # Examples
442
448
///
0 commit comments