@@ -1825,10 +1825,24 @@ pub trait Iterator {
1825
1825
Inspect :: new ( self , f)
1826
1826
}
1827
1827
1828
- /// Borrows an iterator, rather than consuming it.
1829
- ///
1830
- /// This is useful to allow applying iterator adapters while still
1831
- /// retaining ownership of the original iterator.
1828
+ /// Most `Iterator` methods, other than the `next` method (and this one),
1829
+ /// are consuming methods; they move the iterator, taking ownership of it,
1830
+ /// via their `self` parameter (and then mutating it privately).
1831
+ /// Usually, this is fine, though sometimes you want to
1832
+ /// mutate the original iterator without giving up ownership of it.
1833
+ /// That is where this method comes in.
1834
+ ///
1835
+ /// The return value of this method acts like the original iterator,
1836
+ /// except that all consuming methods behave like mutating methods,
1837
+ /// which mutate the original iterator, without taking ownership of it.
1838
+ ///
1839
+ /// This works, because the mutable reference that this method returns,
1840
+ /// implements the `Iterator` trait in its own right via:
1841
+ /// [impl<I: Iterator + ?Sized> Iterator for &mut I { type Item = I::Item; ...}](trait.Iterator.html#impl-Iterator-for-%26mut I).
1842
+ /// This implementation simply passes all method calls on to the original iterator,
1843
+ /// allowing you to call a consuming iterator method on the mutable reference,
1844
+ /// which will mutate the original,
1845
+ /// without giving up ownership of the original iterator.
1832
1846
///
1833
1847
/// # Examples
1834
1848
///
@@ -4019,6 +4033,7 @@ where
4019
4033
}
4020
4034
}
4021
4035
4036
+ /// Implements Iterator for mutable references to Iterator, such as those produced by [Iterator::by_ref]
4022
4037
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4023
4038
impl < I : Iterator + ?Sized > Iterator for & mut I {
4024
4039
type Item = I :: Item ;
0 commit comments