]> git.lizzy.rs Git - rust.git/commitdiff
Add documentation example for `str::Chars::as_str`.
authorCorey Farwell <coreyf@rwell.org>
Wed, 27 Jul 2016 02:52:56 +0000 (22:52 -0400)
committerCorey Farwell <coreyf@rwell.org>
Thu, 28 Jul 2016 12:54:48 +0000 (08:54 -0400)
src/libcore/str/mod.rs

index a32c9da9815ffc0a19d0cfdeec1138ccd6097b3d..fdcadd43a0fb64deeda403b43c42ebf3a74c4277 100644 (file)
@@ -459,6 +459,19 @@ impl<'a> Chars<'a> {
     ///
     /// This has the same lifetime as the original slice, and so the
     /// iterator can continue to be used while this exists.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let mut chars = "abc".chars();
+    ///
+    /// assert_eq!(chars.as_str(), "abc");
+    /// chars.next();
+    /// assert_eq!(chars.as_str(), "bc");
+    /// chars.next();
+    /// chars.next();
+    /// assert_eq!(chars.as_str(), "");
+    /// ```
     #[stable(feature = "iter_to_slice", since = "1.4.0")]
     #[inline]
     pub fn as_str(&self) -> &'a str {