Use slice instead of array in iterator1

This avoids confusion between `.into_iter()` and `.iter()`. On a slice,
both methods do the same (correct) thing. Using `.into_iter()` will
result in a clippy warning about the slice not being consumed.
This commit is contained in:
Remo Senekowitsch 2026-05-03 14:54:27 +02:00
parent 4f1a440962
commit 124708acd9
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View File

@ -10,9 +10,9 @@ fn main() {
mod tests {
#[test]
fn iterators() {
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
let my_fav_fruits = &["banana", "custard apple", "avocado", "peach", "raspberry"];
// TODO: Create an iterator over the array.
// TODO: Create an iterator over the slice.
let mut fav_fruits_iterator = todo!();
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));

View File

@ -10,9 +10,9 @@ fn main() {
mod tests {
#[test]
fn iterators() {
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
let my_fav_fruits = &["banana", "custard apple", "avocado", "peach", "raspberry"];
// Create an iterator over the array.
// Create an iterator over the slice.
let mut fav_fruits_iterator = my_fav_fruits.iter();
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));