]> git.lizzy.rs Git - rust.git/commitdiff
Rewrite `slice::chunks` doc example to not require printing.
authorCorey Farwell <coreyf@rwell.org>
Sun, 31 Jul 2016 03:21:48 +0000 (23:21 -0400)
committerCorey Farwell <coreyf@rwell.org>
Sun, 31 Jul 2016 03:21:48 +0000 (23:21 -0400)
src/libcollections/slice.rs

index ccef6c02f9d22f4d15aa3aded94270d16d847a9e..ff2b8cdea22789076a31416392827ecfee6ba742 100644 (file)
@@ -577,15 +577,13 @@ pub fn windows(&self, size: usize) -> Windows<T> {
     ///
     /// # Example
     ///
-    /// Print the slice two elements at a time (i.e. `[1,2]`,
-    /// `[3,4]`, `[5]`):
-    ///
-    /// ```rust
-    /// let v = &[1, 2, 3, 4, 5];
-    ///
-    /// for chunk in v.chunks(2) {
-    ///     println!("{:?}", chunk);
-    /// }
+    /// ```
+    /// let slice = ['l', 'o', 'r', 'e', 'm'];
+    /// let mut iter = slice.chunks(2);
+    /// assert_eq!(iter.next().unwrap(), &['l', 'o']);
+    /// assert_eq!(iter.next().unwrap(), &['r', 'e']);
+    /// assert_eq!(iter.next().unwrap(), &['m']);
+    /// assert!(iter.next().is_none());
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]