We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bfb0279 commit c1df9f1Copy full SHA for c1df9f1
library/core/src/iter/traits/iterator.rs
@@ -1535,6 +1535,21 @@ pub trait Iterator {
1535
///
1536
/// # Examples
1537
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
1553
/// This demonstrates a use case that needs `by_ref`:
1554
1555
/// ```compile_fail,E0382
0 commit comments