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