File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
library/core/src/iter/traits Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -1535,6 +1535,21 @@ pub trait Iterator {
15351535 ///
15361536 /// # Examples
15371537 ///
1538+ /// Basic usage:
1539+ ///
1540+ /// ```
1541+ /// let mut words = vec!["hello", "world", "of", "Rust"].into_iter();
1542+ ///
1543+ /// // Take the first two words.
1544+ /// let hello_world: Vec<_> = words.by_ref().take(2).collect();
1545+ /// assert_eq!(hello_world, vec!["hello", "world"]);
1546+ ///
1547+ /// // Collect the rest of the words.
1548+ /// // We can only do this because we used `by_ref` earlier.
1549+ /// let of_rust: Vec<_> = words.collect();
1550+ /// assert_eq!(of_rust, vec!["of", "Rust"]);
1551+ /// ```
1552+ ///
15381553 /// This demonstrates a use case that needs `by_ref`:
15391554 ///
15401555 /// ```compile_fail,E0382
You can’t perform that action at this time.
0 commit comments