Skip to content

Commit 4529e50

Browse files
authored
Rollup merge of rust-lang#135987 - hkBst:patch-20, r=joboet
Clarify iterator by_ref docs fixes rust-lang#95143
2 parents 374ce1f + 506c304 commit 4529e50

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
///
@@ -4024,6 +4033,9 @@ where
40244033
}
40254034
}
40264035

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

0 commit comments

Comments
 (0)