Skip to content

Commit 469b7fd

Browse files
split example into three sections with explanation
1 parent c186da7 commit 469b7fd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/libcore/ops.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,13 +1462,24 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
14621462
///
14631463
/// # Examples
14641464
///
1465+
/// The `..` syntax is a `RangeFull`:
1466+
///
14651467
/// ```
14661468
/// assert_eq!((..), std::ops::RangeFull);
1469+
/// ```
14671470
///
1468-
/// // for i in .. {
1469-
/// // println!("This errors because .. has no IntoIterator impl");
1470-
/// // }
1471+
/// It does not have an `IntoIterator` implementation, so you can't use it in a
1472+
/// `for` loop directly. This won't compile:
14711473
///
1474+
/// ```ignore
1475+
/// for i in .. {
1476+
/// // ...
1477+
/// }
1478+
/// ```
1479+
///
1480+
/// Used as a slicing index, `RangeFull` produces the full array as a slice.
1481+
///
1482+
/// ```
14721483
/// let arr = [0, 1, 2, 3];
14731484
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
14741485
/// assert_eq!(arr[ ..3], [0,1,2 ]);

0 commit comments

Comments
 (0)