Skip to content

Commit 2effa89

Browse files
authored
Rollup merge of #35134 - frewsxcv:slice-chunks, r=GuillaumeGomez
Rewrite `slice::chunks` doc example to not require printing. None
2 parents 518524d + 2eea1f3 commit 2effa89

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/libcollections/slice.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,13 @@ impl<T> [T] {
577577
///
578578
/// # Example
579579
///
580-
/// Print the slice two elements at a time (i.e. `[1,2]`,
581-
/// `[3,4]`, `[5]`):
582-
///
583-
/// ```rust
584-
/// let v = &[1, 2, 3, 4, 5];
585-
///
586-
/// for chunk in v.chunks(2) {
587-
/// println!("{:?}", chunk);
588-
/// }
580+
/// ```
581+
/// let slice = ['l', 'o', 'r', 'e', 'm'];
582+
/// let mut iter = slice.chunks(2);
583+
/// assert_eq!(iter.next().unwrap(), &['l', 'o']);
584+
/// assert_eq!(iter.next().unwrap(), &['r', 'e']);
585+
/// assert_eq!(iter.next().unwrap(), &['m']);
586+
/// assert!(iter.next().is_none());
589587
/// ```
590588
#[stable(feature = "rust1", since = "1.0.0")]
591589
#[inline]

0 commit comments

Comments
 (0)