@@ -101,16 +101,11 @@ pub trait Iterator {
101
101
fn size_hint ( & self ) -> ( usize , Option < usize > ) { ( 0 , None ) }
102
102
}
103
103
104
- impl < ' a , T > Iterator for & ' a mut ( Iterator < Item =T > + ' a ) {
105
- type Item = T ;
106
-
107
- fn next ( & mut self ) -> Option < T > {
108
- ( * * self ) . next ( )
109
- }
110
-
111
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
112
- ( * * self ) . size_hint ( )
113
- }
104
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
105
+ impl < ' a , I : Iterator + ?Sized > Iterator for & ' a mut I {
106
+ type Item = I :: Item ;
107
+ fn next ( & mut self ) -> Option < I :: Item > { ( * * self ) . next ( ) }
108
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { ( * * self ) . size_hint ( ) }
114
109
}
115
110
116
111
/// Conversion from an `Iterator`
@@ -549,9 +544,7 @@ pub trait IteratorExt: Iterator + Sized {
549
544
/// assert!(it.next() == Some(5));
550
545
/// ```
551
546
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
552
- fn by_ref < ' r > ( & ' r mut self ) -> ByRef < ' r , Self > {
553
- ByRef { iter : self }
554
- }
547
+ fn by_ref ( & mut self ) -> & mut Self { self }
555
548
556
549
/// Loops through the entire iterator, collecting all of the elements into
557
550
/// a container implementing `FromIterator`.
@@ -1019,15 +1012,22 @@ impl<I> IteratorExt for I where I: Iterator {}
1019
1012
1020
1013
/// A range iterator able to yield elements from both ends
1021
1014
///
1022
- /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
1023
- /// elements from the *same* range, and do not work independently of each other.
1015
+ /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and
1016
+ /// `next_back()` exhaust elements from the *same* range, and do not work
1017
+ /// independently of each other.
1024
1018
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1025
1019
pub trait DoubleEndedIterator : Iterator {
1026
- /// Yield an element from the end of the range, returning `None` if the range is empty.
1020
+ /// Yield an element from the end of the range, returning `None` if the
1021
+ /// range is empty.
1027
1022
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1028
1023
fn next_back ( & mut self ) -> Option < Self :: Item > ;
1029
1024
}
1030
1025
1026
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1027
+ impl < ' a , I : DoubleEndedIterator + ?Sized > DoubleEndedIterator for & ' a mut I {
1028
+ fn next_back ( & mut self ) -> Option < I :: Item > { ( * * self ) . next_back ( ) }
1029
+ }
1030
+
1031
1031
/// An object implementing random access indexing by `usize`
1032
1032
///
1033
1033
/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
@@ -1067,6 +1067,9 @@ pub trait ExactSizeIterator: Iterator {
1067
1067
}
1068
1068
}
1069
1069
1070
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1071
+ impl < ' a , I : ExactSizeIterator + ?Sized > ExactSizeIterator for & ' a mut I { }
1072
+
1070
1073
// All adaptors that preserve the size of the wrapped iterator are fine
1071
1074
// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
1072
1075
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1119,32 +1122,6 @@ impl<I> RandomAccessIterator for Rev<I> where I: DoubleEndedIterator + RandomAcc
1119
1122
}
1120
1123
}
1121
1124
1122
- /// A mutable reference to an iterator
1123
- #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
1124
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1125
- pub struct ByRef < ' a , I : ' a > {
1126
- iter : & ' a mut I ,
1127
- }
1128
-
1129
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1130
- impl < ' a , I > Iterator for ByRef < ' a , I > where I : ' a + Iterator {
1131
- type Item = <I as Iterator >:: Item ;
1132
-
1133
- #[ inline]
1134
- fn next ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next ( ) }
1135
- #[ inline]
1136
- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
1137
- }
1138
-
1139
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1140
- impl < ' a , I > DoubleEndedIterator for ByRef < ' a , I > where I : ' a + DoubleEndedIterator {
1141
- #[ inline]
1142
- fn next_back ( & mut self ) -> Option < <I as Iterator >:: Item > { self . iter . next_back ( ) }
1143
- }
1144
-
1145
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1146
- impl < ' a , I > ExactSizeIterator for ByRef < ' a , I > where I : ' a + ExactSizeIterator { }
1147
-
1148
1125
/// A trait for iterators over elements which can be added together
1149
1126
#[ unstable( feature = "core" ,
1150
1127
reason = "needs to be re-evaluated as part of numerics reform" ) ]
0 commit comments