From 102b3a937b8bb5ef601fd586a3d9ffcd518d6bf3 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 6 Sep 2016 21:10:15 -0400 Subject: [PATCH] Add doc example for `std::time::Instant::elapsed`. --- src/libstd/time/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index 0e1508a1c4c28..154f603c84f16 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -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