Skip to content

Commit

Permalink
set_from: use zip
Browse files Browse the repository at this point in the history
Co-Authored-By: Jack Wrenn <jack@wrenn.fyi>
  • Loading branch information
Philippe-Cholet and jswrenn committed Feb 28, 2024
1 parent 1131899 commit 01e2062
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2222,15 +2222,10 @@ pub trait Itertools: Iterator {
Self: Iterator<Item = &'a mut A>,
J: IntoIterator<Item = A>,
{
let mut count = 0;
for elt in from {
match self.next() {
None => break,
Some(ptr) => *ptr = elt,
}
count += 1;
}
count
from.into_iter()
.zip(self)
.map(|(new, old)| *old = new)
.count()
}

/// Combine all iterator elements into one String, separated by `sep`.
Expand Down

0 comments on commit 01e2062

Please sign in to comment.