Skip to content

Commit

Permalink
Remove redundant second example
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Mar 20, 2021
1 parent c1df9f1 commit 49ccc3f
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,34 +1549,6 @@ pub trait Iterator {
/// let of_rust: Vec<_> = words.collect();
/// assert_eq!(of_rust, vec!["of", "Rust"]);
/// ```
///
/// This demonstrates a use case that needs `by_ref`:
///
/// ```compile_fail,E0382
/// let a = [1, 2, 3, 4, 5];
/// let mut iter = a.iter();
///
/// let sum: i32 = iter.take(3).fold(0, |acc, i| acc + i);
/// assert_eq!(sum, 6);
///
/// // Error! We can't use `iter` again because it was moved
/// // by `take`.
/// assert_eq!(iter.next(), Some(&4));
/// ```
///
/// Now, let's use `by_ref` to make this work:
///
/// ```
/// let a = [1, 2, 3, 4, 5];
/// let mut iter = a.iter();
///
/// // We add in a call to `by_ref` here so `iter` isn't moved.
/// let sum: i32 = iter.by_ref().take(3).fold(0, |acc, i| acc + i);
/// assert_eq!(sum, 6);
///
/// // And now we can use `iter` again because we still own it.
/// assert_eq!(iter.next(), Some(&4));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn by_ref(&mut self) -> &mut Self
where
Expand Down

0 comments on commit 49ccc3f

Please sign in to comment.