9
9
// except according to those terms.
10
10
11
11
//! Temporal quantification.
12
+ //!
13
+ //! Example:
14
+ //!
15
+ //! ```
16
+ //! use std::time::Duration;
17
+ //!
18
+ //! let five_seconds = Duration::new(5, 0);
19
+ //! // both declarations are equivalent
20
+ //! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
21
+ //! ```
12
22
13
23
#![ stable( feature = "time" , since = "1.3.0" ) ]
14
24
@@ -40,6 +50,22 @@ mod duration;
40
50
/// no method to get "the number of seconds" from an instant. Instead, it only
41
51
/// allows measuring the duration between two instants (or comparing two
42
52
/// instants).
53
+ ///
54
+ /// Example:
55
+ ///
56
+ /// ```no_run
57
+ /// use std::time::{Duration, Instant};
58
+ /// use std::thread::sleep;
59
+ ///
60
+ /// fn main() {
61
+ /// let now = Instant::now();
62
+ ///
63
+ /// // we sleep for 2 seconds
64
+ /// sleep(Duration::new(2, 0));
65
+ /// // it prints '2'
66
+ /// println!("{}", now.elapsed().as_secs());
67
+ /// }
68
+ /// ```
43
69
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
44
70
#[ stable( feature = "time2" , since = "1.8.0" ) ]
45
71
pub struct Instant ( time:: Instant ) ;
@@ -63,6 +89,30 @@ pub struct Instant(time::Instant);
63
89
/// information about a `SystemTime`. By calculating the duration from this
64
90
/// fixed point in time, a `SystemTime` can be converted to a human-readable time,
65
91
/// or perhaps some other string representation.
92
+ ///
93
+ /// Example:
94
+ ///
95
+ /// ```no_run
96
+ /// use std::time::{Duration, SystemTime};
97
+ /// use std::thread::sleep;
98
+ ///
99
+ /// fn main() {
100
+ /// let now = SystemTime::now();
101
+ ///
102
+ /// // we sleep for 2 seconds
103
+ /// sleep(Duration::new(2, 0));
104
+ /// match now.elapsed() {
105
+ /// Ok(elapsed) => {
106
+ /// // it prints '2'
107
+ /// println!("{}", elapsed.as_secs());
108
+ /// }
109
+ /// Err(e) => {
110
+ /// // an error occured!
111
+ /// println!("Error: {:?}", e);
112
+ /// }
113
+ /// }
114
+ /// }
115
+ /// ```
66
116
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
67
117
#[ stable( feature = "time2" , since = "1.8.0" ) ]
68
118
pub struct SystemTime ( time:: SystemTime ) ;
0 commit comments