Skip to content

Commit

Permalink
Rollup merge of rust-lang#36311 - frewsxcv:instant-elapsed-example, r…
Browse files Browse the repository at this point in the history
…=GuillaumeGomez

Add doc example for `std::time::Instant::elapsed`.

None
  • Loading branch information
GuillaumeGomez authored Sep 10, 2016
2 parents 26315bf + 102b3a9 commit 30198bf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ impl Instant {
/// This function may panic if the current time is earlier than this
/// instant, which is something that can happen if an `Instant` is
/// produced synthetically.
///
/// # Examples
///
/// ```no_run
/// use std::thread::sleep;
/// use std::time::{Duration, Instant};
///
/// let instant = Instant::now();
/// let three_secs = Duration::from_secs(3);
/// sleep(three_secs);
/// assert!(instant.elapsed() >= three_secs);
/// ```
#[stable(feature = "time2", since = "1.8.0")]
pub fn elapsed(&self) -> Duration {
Instant::now() - *self
Expand Down

0 comments on commit 30198bf

Please sign in to comment.