@@ -92,6 +92,29 @@ impl<Idx: fmt::Debug> fmt::Debug for Range<Idx> {
92
92
}
93
93
}
94
94
95
+ impl < Idx : Step > Range < Idx > {
96
+ /// Create an iterator over the elements within this range.
97
+ ///
98
+ /// Shorthand for `.clone().into_iter()`
99
+ ///
100
+ /// # Examples
101
+ ///
102
+ /// ```
103
+ /// #![feature(new_range_api)]
104
+ /// use core::range::Range;
105
+ ///
106
+ /// let mut i = Range::from(3..9).iter().map(|n| n*n);
107
+ /// assert_eq!(i.next(), Some(9));
108
+ /// assert_eq!(i.next(), Some(16));
109
+ /// assert_eq!(i.next(), Some(25));
110
+ /// ```
111
+ #[ unstable( feature = "new_range_api" , issue = "125687" ) ]
112
+ #[ inline]
113
+ pub fn iter ( & self ) -> IterRange < Idx > {
114
+ self . clone ( ) . into_iter ( )
115
+ }
116
+ }
117
+
95
118
impl < Idx : PartialOrd < Idx > > Range < Idx > {
96
119
/// Returns `true` if `item` is contained in the range.
97
120
///
@@ -289,6 +312,29 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
289
312
}
290
313
}
291
314
315
+ impl < Idx : Step > RangeInclusive < Idx > {
316
+ /// Create an iterator over the elements within this range.
317
+ ///
318
+ /// Shorthand for `.clone().into_iter()`
319
+ ///
320
+ /// # Examples
321
+ ///
322
+ /// ```
323
+ /// #![feature(new_range_api)]
324
+ /// use core::range::RangeInclusive;
325
+ ///
326
+ /// let mut i = RangeInclusive::from(3..=8).iter().map(|n| n*n);
327
+ /// assert_eq!(i.next(), Some(9));
328
+ /// assert_eq!(i.next(), Some(16));
329
+ /// assert_eq!(i.next(), Some(25));
330
+ /// ```
331
+ #[ unstable( feature = "new_range_api" , issue = "125687" ) ]
332
+ #[ inline]
333
+ pub fn iter ( & self ) -> IterRangeInclusive < Idx > {
334
+ self . clone ( ) . into_iter ( )
335
+ }
336
+ }
337
+
292
338
impl RangeInclusive < usize > {
293
339
/// Converts to an exclusive `Range` for `SliceIndex` implementations.
294
340
/// The caller is responsible for dealing with `end == usize::MAX`.
@@ -382,6 +428,29 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeFrom<Idx> {
382
428
}
383
429
}
384
430
431
+ impl < Idx : Step > RangeFrom < Idx > {
432
+ /// Create an iterator over the elements within this range.
433
+ ///
434
+ /// Shorthand for `.clone().into_iter()`
435
+ ///
436
+ /// # Examples
437
+ ///
438
+ /// ```
439
+ /// #![feature(new_range_api)]
440
+ /// use core::range::RangeFrom;
441
+ ///
442
+ /// let mut i = RangeFrom::from(3..).iter().map(|n| n*n);
443
+ /// assert_eq!(i.next(), Some(9));
444
+ /// assert_eq!(i.next(), Some(16));
445
+ /// assert_eq!(i.next(), Some(25));
446
+ /// ```
447
+ #[ unstable( feature = "new_range_api" , issue = "125687" ) ]
448
+ #[ inline]
449
+ pub fn iter ( & self ) -> IterRangeFrom < Idx > {
450
+ self . clone ( ) . into_iter ( )
451
+ }
452
+ }
453
+
385
454
impl < Idx : PartialOrd < Idx > > RangeFrom < Idx > {
386
455
/// Returns `true` if `item` is contained in the range.
387
456
///
0 commit comments