Skip to content

Commit 102b3a9

Browse files
committed
Add doc example for std::time::Instant::elapsed.
1 parent 923bac4 commit 102b3a9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libstd/time/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ impl Instant {
150150
/// This function may panic if the current time is earlier than this
151151
/// instant, which is something that can happen if an `Instant` is
152152
/// produced synthetically.
153+
///
154+
/// # Examples
155+
///
156+
/// ```no_run
157+
/// use std::thread::sleep;
158+
/// use std::time::{Duration, Instant};
159+
///
160+
/// let instant = Instant::now();
161+
/// let three_secs = Duration::from_secs(3);
162+
/// sleep(three_secs);
163+
/// assert!(instant.elapsed() >= three_secs);
164+
/// ```
153165
#[stable(feature = "time2", since = "1.8.0")]
154166
pub fn elapsed(&self) -> Duration {
155167
Instant::now() - *self

0 commit comments

Comments
 (0)