Skip to content

Commit b1484f5

Browse files
authored
Clarify iterator by_ref docs
1 parent 061ee95 commit b1484f5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

library/core/src/iter/traits/iterator.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1825,10 +1825,16 @@ pub trait Iterator {
18251825
Inspect::new(self, f)
18261826
}
18271827

1828-
/// Borrows an iterator, rather than consuming it.
1828+
/// If you use a consuming method on an iterator,
1829+
/// the iterator is consumed by the method and cannot be used afterwards.
1830+
/// This method allows you to mutably borrow an iterator,
1831+
/// such that consuming methods don't consume the original.
18291832
///
1830-
/// This is useful to allow applying iterator adapters while still
1831-
/// retaining ownership of the original iterator.
1833+
/// This turns an iterator into its mutably-borrowed iterator via
1834+
/// [impl<I: Iterator + ?Sized> Iterator for &mut I { type Item = I::Item; ...}](trait.Iterator.html#impl-Iterator-for-&mut I).
1835+
/// This allows using consuming methods on the mutable borrow,
1836+
/// which then consume the mutable borrow instead of the original,
1837+
/// such that you can continue to use the original iterator afterwards.
18321838
///
18331839
/// # Examples
18341840
///
@@ -4019,6 +4025,7 @@ where
40194025
}
40204026
}
40214027

4028+
/// Implements Iterator for mutable references to Iterator, such as those produced by [Iterator::by_ref]
40224029
#[stable(feature = "rust1", since = "1.0.0")]
40234030
impl<I: Iterator + ?Sized> Iterator for &mut I {
40244031
type Item = I::Item;

0 commit comments

Comments
 (0)