@@ -65,7 +65,7 @@ use default::Default;
65
65
use marker;
66
66
use mem;
67
67
use num:: { ToPrimitive , Int } ;
68
- use ops:: { Add , Deref , FnMut , RangeFrom } ;
68
+ use ops:: { Add , Deref , FnMut } ;
69
69
use option:: Option ;
70
70
use option:: Option :: { Some , None } ;
71
71
use marker:: Sized ;
@@ -2366,101 +2366,34 @@ impl<A, St, F> Iterator for Unfold<St, F> where F: FnMut(&mut St) -> Option<A> {
2366
2366
}
2367
2367
}
2368
2368
2369
- /// An adapter for stepping range iterators by a custom amount.
2370
- ///
2371
- /// The resulting iterator handles overflow by stopping. The `A`
2372
- /// parameter is the type being iterated over, while `R` is the range
2373
- /// type (usually one of `std::ops::{Range, RangeFrom}`.
2374
- #[ derive( Clone ) ]
2375
- #[ unstable( feature = "step_by" , reason = "recent addition" ) ]
2376
- pub struct StepBy < A , R > {
2377
- step_by : A ,
2378
- range : R ,
2379
- }
2380
-
2381
- impl < A : Add > RangeFrom < A > {
2382
- /// Creates an iterator starting at the same point, but stepping by
2383
- /// the given amount at each iteration.
2384
- ///
2385
- /// # Examples
2386
- ///
2387
- /// ```ignore
2388
- /// for i in (0u8..).step_by(2) {
2389
- /// println!("{}", i);
2390
- /// }
2391
- /// ```
2392
- ///
2393
- /// This prints all even `u8` values.
2394
- #[ unstable( feature = "step_by" , reason = "recent addition" ) ]
2395
- pub fn step_by ( self , by : A ) -> StepBy < A , Self > {
2396
- StepBy {
2397
- step_by : by,
2398
- range : self
2399
- }
2400
- }
2401
- }
2402
-
2403
- impl < A : Int > :: ops:: Range < A > {
2404
- /// Creates an iterator with the same range, but stepping by the
2405
- /// given amount at each iteration.
2406
- ///
2407
- /// The resulting iterator handles overflow by stopping.
2408
- ///
2409
- /// # Examples
2410
- ///
2411
- /// ```
2412
- /// # #![feature(step_by, core)]
2413
- /// for i in (0..10).step_by(2) {
2414
- /// println!("{}", i);
2415
- /// }
2416
- /// ```
2417
- ///
2418
- /// This prints:
2419
- ///
2420
- /// ```text
2421
- /// 0
2422
- /// 2
2423
- /// 4
2424
- /// 6
2425
- /// 8
2426
- /// ```
2427
- #[ unstable( feature = "step_by" , reason = "recent addition" ) ]
2428
- pub fn step_by ( self , by : A ) -> StepBy < A , Self > {
2429
- StepBy {
2430
- step_by : by,
2431
- range : self
2432
- }
2433
- }
2434
- }
2435
-
2436
2369
/// An infinite iterator starting at `start` and advancing by `step` with each
2437
2370
/// iteration
2371
+ #[ derive( Clone ) ]
2438
2372
#[ unstable( feature = "core" ,
2439
2373
reason = "may be renamed or replaced by range notation adapters" ) ]
2440
- #[ deprecated( since = "1.0.0-beta" , reason = "use range notation and step_by" ) ]
2441
- pub type Counter < A > = StepBy < A , RangeFrom < A > > ;
2374
+ pub struct Counter < A > {
2375
+ /// The current state the counter is at (next value to be yielded)
2376
+ state : A ,
2377
+ /// The amount that this iterator is stepping by
2378
+ step : A ,
2379
+ }
2442
2380
2443
- /// Deprecated: use `( start..).step_by( step)` instead.
2381
+ /// Creates a new counter with the specified start/ step
2444
2382
#[ inline]
2445
2383
#[ unstable( feature = "core" ,
2446
2384
reason = "may be renamed or replaced by range notation adapters" ) ]
2447
- #[ deprecated( since = "1.0.0-beta" , reason = "use (start..).step_by(step) instead" ) ]
2448
- #[ allow( deprecated) ]
2449
2385
pub fn count < A > ( start : A , step : A ) -> Counter < A > {
2450
- StepBy {
2451
- range : RangeFrom { start : start } ,
2452
- step_by : step,
2453
- }
2386
+ Counter { state : start, step : step}
2454
2387
}
2455
2388
2456
2389
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2457
- impl < A : Add < Output =A > + Clone > Iterator for StepBy < A , RangeFrom < A > > {
2390
+ impl < A : Add < Output =A > + Clone > Iterator for Counter < A > {
2458
2391
type Item = A ;
2459
2392
2460
2393
#[ inline]
2461
2394
fn next ( & mut self ) -> Option < A > {
2462
- let result = self . range . start . clone ( ) ;
2463
- self . range . start = result . clone ( ) + self . step_by . clone ( ) ;
2395
+ let result = self . state . clone ( ) ;
2396
+ self . state = self . state . clone ( ) + self . step . clone ( ) ;
2464
2397
Some ( result)
2465
2398
}
2466
2399
@@ -2471,22 +2404,31 @@ impl<A: Add<Output=A> + Clone> Iterator for StepBy<A, RangeFrom<A>> {
2471
2404
}
2472
2405
2473
2406
/// An iterator over the range [start, stop)
2474
- #[ allow( deprecated) ]
2475
2407
#[ derive( Clone ) ]
2476
2408
#[ unstable( feature = "core" ,
2477
2409
reason = "will be replaced by range notation" ) ]
2478
- #[ deprecated( since = "1.0.0-beta" , reason = "use range notation" ) ]
2479
2410
pub struct Range < A > {
2480
2411
state : A ,
2481
2412
stop : A ,
2482
2413
one : A ,
2483
2414
}
2484
2415
2485
- /// Deprecated: use `(start..stop)` instead.
2416
+ /// Returns an iterator over the given range [start, stop) (that is, starting
2417
+ /// at start (inclusive), and ending at stop (exclusive)).
2418
+ ///
2419
+ /// # Examples
2420
+ ///
2421
+ /// ```
2422
+ /// let array = [0, 1, 2, 3, 4];
2423
+ ///
2424
+ /// for i in range(0, 5) {
2425
+ /// println!("{}", i);
2426
+ /// assert_eq!(i, array[i]);
2427
+ /// }
2428
+ /// ```
2486
2429
#[ inline]
2487
- #[ unstable( feature = "core" , reason = "will be replaced by range notation" ) ]
2488
- #[ deprecated( since = "1.0.0-beta" , reason = "use (start..stop) instead" ) ]
2489
- #[ allow( deprecated) ]
2430
+ #[ unstable( feature = "core" ,
2431
+ reason = "will be replaced by range notation" ) ]
2490
2432
pub fn range < A : Int > ( start : A , stop : A ) -> Range < A > {
2491
2433
Range {
2492
2434
state : start,
@@ -2498,8 +2440,6 @@ pub fn range<A: Int>(start: A, stop: A) -> Range<A> {
2498
2440
// FIXME: #10414: Unfortunate type bound
2499
2441
#[ unstable( feature = "core" ,
2500
2442
reason = "will be replaced by range notation" ) ]
2501
- #[ deprecated( since = "1.0.0-beta" , reason = "use range notation" ) ]
2502
- #[ allow( deprecated) ]
2503
2443
impl < A : Int + ToPrimitive > Iterator for Range < A > {
2504
2444
type Item = A ;
2505
2445
@@ -2551,8 +2491,6 @@ impl<A: Int + ToPrimitive> Iterator for Range<A> {
2551
2491
/// the direction it is consumed.
2552
2492
#[ unstable( feature = "core" ,
2553
2493
reason = "will be replaced by range notation" ) ]
2554
- #[ deprecated( since = "1.0.0-beta" , reason = "use range notation" ) ]
2555
- #[ allow( deprecated) ]
2556
2494
impl < A : Int + ToPrimitive > DoubleEndedIterator for Range < A > {
2557
2495
#[ inline]
2558
2496
fn next_back ( & mut self ) -> Option < A > {
@@ -2569,7 +2507,6 @@ impl<A: Int + ToPrimitive> DoubleEndedIterator for Range<A> {
2569
2507
#[ derive( Clone ) ]
2570
2508
#[ unstable( feature = "core" ,
2571
2509
reason = "likely to be replaced by range notation and adapters" ) ]
2572
- #[ allow( deprecated) ]
2573
2510
pub struct RangeInclusive < A > {
2574
2511
range : Range < A > ,
2575
2512
done : bool ,
@@ -2579,7 +2516,6 @@ pub struct RangeInclusive<A> {
2579
2516
#[ inline]
2580
2517
#[ unstable( feature = "core" ,
2581
2518
reason = "likely to be replaced by range notation and adapters" ) ]
2582
- #[ allow( deprecated) ]
2583
2519
pub fn range_inclusive < A : Int > ( start : A , stop : A ) -> RangeInclusive < A > {
2584
2520
RangeInclusive {
2585
2521
range : range ( start, stop) ,
@@ -2589,7 +2525,6 @@ pub fn range_inclusive<A: Int>(start: A, stop: A) -> RangeInclusive<A> {
2589
2525
2590
2526
#[ unstable( feature = "core" ,
2591
2527
reason = "likely to be replaced by range notation and adapters" ) ]
2592
- #[ allow( deprecated) ]
2593
2528
impl < A : Int + ToPrimitive > Iterator for RangeInclusive < A > {
2594
2529
type Item = A ;
2595
2530
@@ -2626,7 +2561,6 @@ impl<A: Int + ToPrimitive> Iterator for RangeInclusive<A> {
2626
2561
2627
2562
#[ unstable( feature = "core" ,
2628
2563
reason = "likely to be replaced by range notation and adapters" ) ]
2629
- #[ allow( deprecated) ]
2630
2564
impl < A : Int + ToPrimitive > DoubleEndedIterator for RangeInclusive < A > {
2631
2565
#[ inline]
2632
2566
fn next_back ( & mut self ) -> Option < A > {
@@ -2644,39 +2578,61 @@ impl<A: Int + ToPrimitive> DoubleEndedIterator for RangeInclusive<A> {
2644
2578
}
2645
2579
2646
2580
/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping.
2581
+ #[ derive( Clone ) ]
2647
2582
#[ unstable( feature = "core" ,
2648
2583
reason = "likely to be replaced by range notation and adapters" ) ]
2649
- #[ deprecated( since = "1.0.0-beta" , reason = "use range notation and step_by" ) ]
2650
- pub type RangeStep < A > = StepBy < A , :: ops:: Range < A > > ;
2584
+ pub struct RangeStep < A > {
2585
+ state : A ,
2586
+ stop : A ,
2587
+ step : A ,
2588
+ rev : bool ,
2589
+ }
2651
2590
2652
- /// Deprecated: use `(start..stop).step_by(step)` instead.
2591
+ /// Return an iterator over the range [start, stop) by `step`.
2592
+ ///
2593
+ /// It handles overflow by stopping.
2594
+ ///
2595
+ /// # Examples
2596
+ ///
2597
+ /// ```
2598
+ /// use std::iter::range_step;
2599
+ ///
2600
+ /// for i in range_step(0, 10, 2) {
2601
+ /// println!("{}", i);
2602
+ /// }
2603
+ /// ```
2604
+ ///
2605
+ /// This prints:
2606
+ ///
2607
+ /// ```text
2608
+ /// 0
2609
+ /// 2
2610
+ /// 4
2611
+ /// 6
2612
+ /// 8
2613
+ /// ```
2653
2614
#[ inline]
2654
2615
#[ unstable( feature = "core" ,
2655
2616
reason = "likely to be replaced by range notation and adapters" ) ]
2656
- #[ deprecated( since = "1.0.0-beta" ,
2657
- reason = "use `(start..stop).step_by(step)` instead" ) ]
2658
- #[ allow( deprecated) ]
2659
2617
pub fn range_step < A : Int > ( start : A , stop : A , step : A ) -> RangeStep < A > {
2660
- StepBy {
2661
- step_by : step,
2662
- range : :: ops:: Range { start : start, end : stop } ,
2663
- }
2618
+ let rev = step < Int :: zero ( ) ;
2619
+ RangeStep { state : start, stop : stop, step : step, rev : rev}
2664
2620
}
2665
2621
2666
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2667
- impl < A : Int > Iterator for StepBy < A , :: ops:: Range < A > > {
2622
+ #[ unstable( feature = "core" ,
2623
+ reason = "likely to be replaced by range notation and adapters" ) ]
2624
+ impl < A : Int > Iterator for RangeStep < A > {
2668
2625
type Item = A ;
2669
2626
2670
2627
#[ inline]
2671
2628
fn next ( & mut self ) -> Option < A > {
2672
- let rev = self . step_by < Int :: zero ( ) ;
2673
- let start = self . range . start ;
2674
- if ( rev && start > self . range . end ) || ( !rev && start < self . range . end ) {
2675
- match start. checked_add ( self . step_by ) {
2676
- Some ( x) => self . range . start = x,
2677
- None => self . range . start = self . range . end . clone ( )
2629
+ if ( self . rev && self . state > self . stop ) || ( !self . rev && self . state < self . stop ) {
2630
+ let result = self . state ;
2631
+ match self . state . checked_add ( self . step ) {
2632
+ Some ( x) => self . state = x,
2633
+ None => self . state = self . stop . clone ( )
2678
2634
}
2679
- Some ( start )
2635
+ Some ( result )
2680
2636
} else {
2681
2637
None
2682
2638
}
0 commit comments