Skip to content

Commit 95fc3f4

Browse files
committed
Standardize Range* documentation
This updates the final example in the documentation for the types `Range`, `RangeFrom`, `RangeFull`, `RangeInclusive`, `RangeTo`, `RangeToInclusive`.
1 parent 26b4cb4 commit 95fc3f4

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

src/libcore/ops/range.rs

+42-26
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ use hash::{Hash, Hasher};
2626
/// Used as a [slicing index], `RangeFull` produces the full array as a slice.
2727
///
2828
/// ```
29-
/// let arr = [0, 1, 2, 3];
30-
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
31-
/// assert_eq!(arr[ ..3], [0,1,2 ]);
32-
/// assert_eq!(arr[1.. ], [ 1,2,3]);
33-
/// assert_eq!(arr[1..3], [ 1,2 ]);
29+
/// let arr = [0, 1, 2, 3, 4];
30+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull
31+
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
32+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
33+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
34+
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
35+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
3436
/// ```
3537
///
3638
/// [`IntoIterator`]: ../iter/trait.Iterator.html
@@ -60,11 +62,13 @@ impl fmt::Debug for RangeFull {
6062
/// assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
6163
/// assert_eq!(3 + 4 + 5, (3..6).sum());
6264
///
63-
/// let arr = ['a', 'b', 'c', 'd'];
64-
/// assert_eq!(arr[ .. ], ['a', 'b', 'c', 'd']);
65-
/// assert_eq!(arr[ ..3], ['a', 'b', 'c', ]);
66-
/// assert_eq!(arr[1.. ], [ 'b', 'c', 'd']);
67-
/// assert_eq!(arr[1..3], [ 'b', 'c' ]); // Range
65+
/// let arr = [0, 1, 2, 3, 4];
66+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]);
67+
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
68+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
69+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
70+
/// assert_eq!(arr[1.. 3], [ 1,2 ]); // Range
71+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
6872
/// ```
6973
#[doc(alias = "..")]
7074
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
@@ -160,11 +164,13 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
160164
/// assert_eq!((2..), std::ops::RangeFrom { start: 2 });
161165
/// assert_eq!(2 + 3 + 4, (2..).take(3).sum());
162166
///
163-
/// let arr = [0, 1, 2, 3];
164-
/// assert_eq!(arr[ .. ], [0,1,2,3]);
165-
/// assert_eq!(arr[ ..3], [0,1,2 ]);
166-
/// assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom
167-
/// assert_eq!(arr[1..3], [ 1,2 ]);
167+
/// let arr = [0, 1, 2, 3, 4];
168+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]);
169+
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
170+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
171+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom
172+
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
173+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
168174
/// ```
169175
///
170176
/// [`Iterator`]: ../iter/trait.IntoIterator.html
@@ -240,11 +246,13 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
240246
/// elements before the index indicated by `end`.
241247
///
242248
/// ```
243-
/// let arr = [0, 1, 2, 3];
244-
/// assert_eq!(arr[ .. ], [0,1,2,3]);
245-
/// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
246-
/// assert_eq!(arr[1.. ], [ 1,2,3]);
247-
/// assert_eq!(arr[1..3], [ 1,2 ]);
249+
/// let arr = [0, 1, 2, 3, 4];
250+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]);
251+
/// assert_eq!(arr[ .. 3], [0,1,2 ]); // RangeTo
252+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
253+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
254+
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
255+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
248256
/// ```
249257
///
250258
/// [`IntoIterator`]: ../iter/trait.Iterator.html
@@ -312,9 +320,13 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
312320
/// assert_eq!((3..=5), std::ops::RangeInclusive::new(3, 5));
313321
/// assert_eq!(3 + 4 + 5, (3..=5).sum());
314322
///
315-
/// let arr = [0, 1, 2, 3];
316-
/// assert_eq!(arr[ ..=2], [0,1,2 ]);
317-
/// assert_eq!(arr[1..=2], [ 1,2 ]); // RangeInclusive
323+
/// let arr = [0, 1, 2, 3, 4];
324+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]);
325+
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
326+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
327+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
328+
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
329+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
318330
/// ```
319331
#[doc(alias = "..=")]
320332
#[derive(Clone)] // not Copy -- see #27186
@@ -569,9 +581,13 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
569581
/// array elements up to and including the index indicated by `end`.
570582
///
571583
/// ```
572-
/// let arr = [0, 1, 2, 3];
573-
/// assert_eq!(arr[ ..=2], [0,1,2 ]); // RangeToInclusive
574-
/// assert_eq!(arr[1..=2], [ 1,2 ]);
584+
/// let arr = [0, 1, 2, 3, 4];
585+
/// assert_eq!(arr[ .. ], [0,1,2,3,4]);
586+
/// assert_eq!(arr[ .. 3], [0,1,2 ]);
587+
/// assert_eq!(arr[ ..=3], [0,1,2,3 ]); // RangeToInclusive
588+
/// assert_eq!(arr[1.. ], [ 1,2,3,4]);
589+
/// assert_eq!(arr[1.. 3], [ 1,2 ]);
590+
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
575591
/// ```
576592
///
577593
/// [`IntoIterator`]: ../iter/trait.Iterator.html

0 commit comments

Comments
 (0)