1
1
//! Temporal quantification.
2
2
//!
3
- //! Example :
3
+ //! # Examples :
4
4
//!
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));
5
18
//! ```
6
- //! use std::time::Duration;
7
19
//!
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());
11
30
//! ```
12
31
13
32
#![ stable( feature = "time" , since = "1.3.0" ) ]
@@ -26,7 +45,7 @@ use crate::sys_common::FromInner;
26
45
pub use core:: time:: Duration ;
27
46
28
47
/// A measurement of a monotonically nondecreasing clock.
29
- /// Opaque and useful only with `Duration`.
48
+ /// Opaque and useful only with [ `Duration`] .
30
49
///
31
50
/// Instants are always guaranteed to be no less than any previously measured
32
51
/// instant when created, and are often useful for tasks such as measuring
0 commit comments