From 01e20623cc9caaf64a21de5f920ad7cb9b730ace Mon Sep 17 00:00:00 2001 From: Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:29:44 +0100 Subject: [PATCH] `set_from`: use `zip` Co-Authored-By: Jack Wrenn --- src/lib.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2956d302c..0506a3d84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2222,15 +2222,10 @@ pub trait Itertools: Iterator { Self: Iterator, J: IntoIterator, { - 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`.