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