about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-09-10 15:57:50 +0200
committerGitHub <noreply@github.com>2016-09-10 15:57:50 +0200
commit30198bf6b65dabc704dfa25ca514e95c817831f6 (patch)
tree4bc382a2462d203e6d9f14e1d09244e5170088d6 /src/libstd
parent26315bf0152c166d922de149c3ad4b5b04f56265 (diff)
parent102b3a937b8bb5ef601fd586a3d9ffcd518d6bf3 (diff)
downloadrust-30198bf6b65dabc704dfa25ca514e95c817831f6.tar.gz
rust-30198bf6b65dabc704dfa25ca514e95c817831f6.zip
Rollup merge of #36311 - frewsxcv:instant-elapsed-example, r=GuillaumeGomez
Add doc example for `std::time::Instant::elapsed`.

None
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/time/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs
index 0e1508a1c4c..154f603c84f 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