11//! Temporal quantification.
22//!
3- //! Example :
3+ //! # Examples :
44//!
5+ //! There are multiple ways to create a new [`Duration`]:
6+ //!
7+ //! ```
8+ //! # use std::time::Duration;
9+ //! let five_seconds = Duration::from_secs(5);
10+ //! assert_eq!(five_seconds, Duration::from_millis(5_000));
11+ //! assert_eq!(five_seconds, Duration::from_micros(5_000_000));
12+ //! assert_eq!(five_seconds, Duration::from_nanos(5_000_000_000));
13+ //!
14+ //! let ten_seconds = Duration::from_secs(10);
15+ //! let seven_nanos = Duration::from_nanos(7);
16+ //! let total = ten_seconds + seven_nanos;
17+ //! assert_eq!(total, Duration::new(10, 7));
518//! ```
6- //! use std::time::Duration;
719//!
8- //! let five_seconds = Duration::new(5, 0);
9- //! // both declarations are equivalent
10- //! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
20+ //! Using [`Instant`] to calculate how long a function took to run:
21+ //!
22+ //! ```ignore (incomplete)
23+ //! let now = Instant::now();
24+ //!
25+ //! // Calling a slow function, it may take a while
26+ //! slow_function();
27+ //!
28+ //! let elapsed_time = now.elapsed();
29+ //! println!("Running slow_function() took {} seconds.", elapsed_time.as_secs());
1130//! ```
1231
1332#![ stable( feature = "time" , since = "1.3.0" ) ]
@@ -26,7 +45,7 @@ use crate::sys_common::FromInner;
2645pub use core:: time:: Duration ;
2746
2847/// A measurement of a monotonically nondecreasing clock.
29- /// Opaque and useful only with `Duration`.
48+ /// Opaque and useful only with [ `Duration`] .
3049///
3150/// Instants are always guaranteed to be no less than any previously measured
3251/// instant when created, and are often useful for tasks such as measuring
0 commit comments