File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 60
60
self . it . map ( T :: clone) . fold ( init, f)
61
61
}
62
62
63
+ #[ inline]
64
+ fn advance_by ( & mut self , n : usize ) -> Result < ( ) , usize > {
65
+ self . it . advance_by ( n)
66
+ }
67
+
63
68
#[ doc( hidden) ]
64
69
unsafe fn __iterator_get_unchecked ( & mut self , idx : usize ) -> T
65
70
where
@@ -96,6 +101,11 @@ where
96
101
{
97
102
self . it . map ( T :: clone) . rfold ( init, f)
98
103
}
104
+
105
+ #[ inline]
106
+ fn advance_back_by ( & mut self , n : usize ) -> Result < ( ) , usize > {
107
+ self . it . advance_back_by ( n)
108
+ }
99
109
}
100
110
101
111
#[ stable( feature = "iter_cloned" , since = "1.1.0" ) ]
Original file line number Diff line number Diff line change @@ -107,8 +107,14 @@ pub trait DoubleEndedIterator: Iterator {
107
107
/// outer iterator until it finds an inner iterator that is not empty, which then often
108
108
/// allows it to return a more accurate `size_hint()` than in its initial state.
109
109
///
110
+ /// Implementations may elide side-effects such as calling closures or `clone` when they are
111
+ /// not necessary to determine by how many steps an iterator can be advanced. For example
112
+ /// [`Cloned::advance_back_by`] avoids unnecessary allocations by directly advancing its inner iterator
113
+ /// instead.
114
+ ///
110
115
/// [`advance_by`]: Iterator::advance_by
111
116
/// [`Flatten`]: crate::iter::Flatten
117
+ /// [`Cloned::advance_back_by`]: crate::iter::Cloned::advance_back_by
112
118
/// [`next_back`]: DoubleEndedIterator::next_back
113
119
///
114
120
/// # Examples
Original file line number Diff line number Diff line change @@ -250,7 +250,13 @@ pub trait Iterator {
250
250
/// can advance its outer iterator until it finds an inner iterator that is not empty, which
251
251
/// then often allows it to return a more accurate `size_hint()` than in its initial state.
252
252
///
253
+ /// Implementations may elide side-effects such as calling closures or `clone` when they are
254
+ /// not necessary to determine by how many steps an iterator can be advanced. For example
255
+ /// [`Cloned::advance_by`] avoids unnecessary allocations by directly advancing its inner iterator
256
+ /// instead.
257
+ ///
253
258
/// [`Flatten`]: crate::iter::Flatten
259
+ /// [`Cloned::advance_by`]: crate::iter::Cloned::advance_by
254
260
/// [`next`]: Iterator::next
255
261
///
256
262
/// # Examples
You can’t perform that action at this time.
0 commit comments