1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2026-05-16 09:38:12 +02:00

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
2 changed files with 4 additions and 4 deletions
+2 -2
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"));
+2 -2
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"));