mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Rollup merge of #36311 - frewsxcv:instant-elapsed-example, r=GuillaumeGomez
Add doc example for `std::time::Instant::elapsed`. None
This commit is contained in:
commit
30198bf6b6
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user