From 2e8d5d3d9c3b01f03aee6ae5581dd47a64af9119 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Mon, 16 Dec 2024 12:22:44 -0800 Subject: [PATCH] Use `.iter()` instead of `(&values).into_iter()` (#2519) The `(&values).into_iter()` construct used in the solution to the iterators exercise is kind of awkward and always gets questions from students. I think the better thing would be to use the `iter` method to get the initial iterator, as that's the more idiomatic way to. It's also an opportunity to point out that there are helper methods for getting an iterator for a collection. --- src/iterators/exercise.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iterators/exercise.rs b/src/iterators/exercise.rs index f95bb031..63c6a9b6 100644 --- a/src/iterators/exercise.rs +++ b/src/iterators/exercise.rs @@ -22,8 +22,8 @@ /// Element `n` of the result is `values[(n+offset)%len] - values[n]`. fn offset_differences(offset: usize, values: Vec) -> Vec { // ANCHOR_END: offset_differences - let a = (&values).into_iter(); - let b = (&values).into_iter().cycle().skip(offset); + let a = values.iter(); + let b = values.iter().cycle().skip(offset); a.zip(b).map(|(a, b)| *b - *a).collect() }