Skip to content

Commit 506c304

Browse files
committed
Clarify iterator by_ref docs
1 parent 061ee95 commit 506c304

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

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

1828-
/// Borrows an iterator, rather than consuming it.
1828+
/// Creates a "by reference" adapter for this instance of `Iterator`.
18291829
///
1830-
/// This is useful to allow applying iterator adapters while still
1831-
/// retaining ownership of the original iterator.
1830+
/// Consuming method calls (direct or indirect calls to `next`)
1831+
/// on the "by reference" adapter will consume the original iterator,
1832+
/// but ownership-taking methods (those with a `self` parameter)
1833+
/// only take ownership of the "by reference" iterator.
1834+
///
1835+
/// This is useful for applying ownership-taking methods
1836+
/// (such as `take` in the example below)
1837+
/// without giving up ownership of the original iterator,
1838+
/// so you can use the original iterator afterwards.
1839+
///
1840+
/// Uses [impl<I: Iterator + ?Sized> Iterator for &mut I { type Item = I::Item; ...}](https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#impl-Iterator-for-%26mut+I).
18321841
///
18331842
/// # Examples
18341843
///
@@ -4019,6 +4028,9 @@ where
40194028
}
40204029
}
40214030

4031+
/// Implements `Iterator` for mutable references to iterators, such as those produced by [`Iterator::by_ref`].
4032+
///
4033+
/// This implementation passes all method calls on to the original iterator.
40224034
#[stable(feature = "rust1", since = "1.0.0")]
40234035
impl<I: Iterator + ?Sized> Iterator for &mut I {
40244036
type Item = I::Item;

0 commit comments

Comments
 (0)