]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `std::time::Instant::elapsed`.
authorCorey Farwell <coreyf@rwell.org>
Wed, 7 Sep 2016 01:10:15 +0000 (21:10 -0400)
committerCorey Farwell <coreyf@rwell.org>
Wed, 7 Sep 2016 13:23:17 +0000 (09:23 -0400)
src/libstd/time/mod.rs

index 0e1508a1c4c28d130baf1813096a7c5ac2960cc8..154f603c84f162f591c7fd75b8b8541676ca6024 100644 (file)
@@ -150,6 +150,18 @@ pub fn duration_since(&self, earlier: Instant) -> Duration {
     /// 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