@@ -19,20 +19,20 @@ use crate::hash::Hash;
19
19
///
20
20
/// ```compile_fail,E0277
21
21
/// for i in .. {
22
- /// // ...
22
+ /// // ...
23
23
/// }
24
24
/// ```
25
25
///
26
26
/// Used as a [slicing index], `RangeFull` produces the full array as a slice.
27
27
///
28
28
/// ```
29
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 ]);
30
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]); // This is the ` 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 ]);
36
36
/// ```
37
37
///
38
38
/// [slicing index]: crate::slice::SliceIndex
@@ -52,22 +52,26 @@ impl fmt::Debug for RangeFull {
52
52
/// A (half-open) range bounded inclusively below and exclusively above
53
53
/// (`start..end`).
54
54
///
55
- /// The `Range` `start..end` contains all values with `x >= start` and
56
- /// `x < end`. It is empty unless `start < end`.
55
+ /// The range `start..end` contains all values with `start <= x < end`.
56
+ /// It is empty if `start >= end`.
57
57
///
58
58
/// # Examples
59
59
///
60
+ /// The `start..end` syntax is a `Range`:
61
+ ///
60
62
/// ```
61
63
/// assert_eq!((3..5), std::ops::Range { start: 3, end: 5 });
62
64
/// assert_eq!(3 + 4 + 5, (3..6).sum());
65
+ /// ```
63
66
///
67
+ /// ```
64
68
/// let arr = [0, 1, 2, 3, 4];
65
- /// assert_eq!(arr[ .. ], [0,1,2,3, 4]);
66
- /// assert_eq!(arr[ .. 3], [0,1,2 ]);
67
- /// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
68
- /// assert_eq!(arr[1.. ], [ 1,2,3, 4]);
69
- /// assert_eq!(arr[1.. 3], [ 1, 2 ]); // Range
70
- /// assert_eq!(arr[1..=3], [ 1,2,3 ]);
69
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
70
+ /// assert_eq!(arr[ .. 3], [0, 1, 2 ]);
71
+ /// assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]);
72
+ /// assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
73
+ /// assert_eq!(arr[1.. 3], [ 1, 2 ]); // This is a ` Range`
74
+ /// assert_eq!(arr[1..=3], [ 1, 2, 3 ]);
71
75
/// ```
72
76
#[ lang = "Range" ]
73
77
#[ doc( alias = ".." ) ]
@@ -160,17 +164,21 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
160
164
///
161
165
/// # Examples
162
166
///
167
+ /// The `start..` syntax is a `RangeFrom`:
168
+ ///
163
169
/// ```
164
170
/// assert_eq!((2..), std::ops::RangeFrom { start: 2 });
165
171
/// assert_eq!(2 + 3 + 4, (2..).take(3).sum());
172
+ /// ```
166
173
///
174
+ /// ```
167
175
/// 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 ]);
176
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
177
+ /// assert_eq!(arr[ .. 3], [0, 1, 2 ]);
178
+ /// assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]);
179
+ /// assert_eq!(arr[1.. ], [ 1, 2, 3, 4]); // This is a ` RangeFrom`
180
+ /// assert_eq!(arr[1.. 3], [ 1, 2 ]);
181
+ /// assert_eq!(arr[1..=3], [ 1, 2, 3 ]);
174
182
/// ```
175
183
#[ lang = "RangeFrom" ]
176
184
#[ doc( alias = ".." ) ]
@@ -244,12 +252,12 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
244
252
///
245
253
/// ```
246
254
/// let arr = [0, 1, 2, 3, 4];
247
- /// assert_eq!(arr[ .. ], [0,1,2,3, 4]);
248
- /// assert_eq!(arr[ .. 3], [0,1, 2 ]); // RangeTo
249
- /// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
250
- /// assert_eq!(arr[1.. ], [ 1,2,3, 4]);
251
- /// assert_eq!(arr[1.. 3], [ 1,2 ]);
252
- /// assert_eq!(arr[1..=3], [ 1,2,3 ]);
255
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
256
+ /// assert_eq!(arr[ .. 3], [0, 1, 2 ]); // This is a ` RangeTo`
257
+ /// assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]);
258
+ /// assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
259
+ /// assert_eq!(arr[1.. 3], [ 1, 2 ]);
260
+ /// assert_eq!(arr[1..=3], [ 1, 2, 3 ]);
253
261
/// ```
254
262
///
255
263
/// [slicing index]: crate::slice::SliceIndex
@@ -310,17 +318,21 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
310
318
///
311
319
/// # Examples
312
320
///
321
+ /// The `start..=end` syntax is a `RangeInclusive`:
322
+ ///
313
323
/// ```
314
324
/// assert_eq!((3..=5), std::ops::RangeInclusive::new(3, 5));
315
325
/// assert_eq!(3 + 4 + 5, (3..=5).sum());
326
+ /// ```
316
327
///
328
+ /// ```
317
329
/// let arr = [0, 1, 2, 3, 4];
318
- /// assert_eq!(arr[ .. ], [0,1,2,3, 4]);
319
- /// assert_eq!(arr[ .. 3], [0,1,2 ]);
320
- /// assert_eq!(arr[ ..=3], [0,1,2,3 ]);
321
- /// assert_eq!(arr[1.. ], [ 1,2,3, 4]);
322
- /// assert_eq!(arr[1.. 3], [ 1,2 ]);
323
- /// assert_eq!(arr[1..=3], [ 1,2, 3 ]); // RangeInclusive
330
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
331
+ /// assert_eq!(arr[ .. 3], [0, 1, 2 ]);
332
+ /// assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]);
333
+ /// assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
334
+ /// assert_eq!(arr[1.. 3], [ 1, 2 ]);
335
+ /// assert_eq!(arr[1..=3], [ 1, 2, 3 ]); // This is a ` RangeInclusive`
324
336
/// ```
325
337
#[ lang = "RangeInclusive" ]
326
338
#[ doc( alias = "..=" ) ]
@@ -534,12 +546,12 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
534
546
///
535
547
/// ```
536
548
/// let arr = [0, 1, 2, 3, 4];
537
- /// assert_eq!(arr[ .. ], [0,1,2,3, 4]);
538
- /// assert_eq!(arr[ .. 3], [0,1,2 ]);
539
- /// assert_eq!(arr[ ..=3], [0,1,2, 3 ]); // RangeToInclusive
540
- /// assert_eq!(arr[1.. ], [ 1,2,3, 4]);
541
- /// assert_eq!(arr[1.. 3], [ 1,2 ]);
542
- /// assert_eq!(arr[1..=3], [ 1,2,3 ]);
549
+ /// assert_eq!(arr[ .. ], [0, 1, 2, 3, 4]);
550
+ /// assert_eq!(arr[ .. 3], [0, 1, 2 ]);
551
+ /// assert_eq!(arr[ ..=3], [0, 1, 2, 3 ]); // This is a ` RangeToInclusive`
552
+ /// assert_eq!(arr[1.. ], [ 1, 2, 3, 4]);
553
+ /// assert_eq!(arr[1.. 3], [ 1, 2 ]);
554
+ /// assert_eq!(arr[1..=3], [ 1, 2, 3 ]);
543
555
/// ```
544
556
///
545
557
/// [slicing index]: crate::slice::SliceIndex
@@ -661,9 +673,9 @@ impl<T: Clone> Bound<&T> {
661
673
}
662
674
}
663
675
664
- #[ stable( feature = "collections_range" , since = "1.28.0" ) ]
665
676
/// `RangeBounds` is implemented by Rust's built-in range types, produced
666
677
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`.
678
+ #[ stable( feature = "collections_range" , since = "1.28.0" ) ]
667
679
pub trait RangeBounds < T : ?Sized > {
668
680
/// Start index bound.
669
681
///
0 commit comments