mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 09:48:45 +00: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:
parent
4f1a440962
commit
124708acd9
@ -10,9 +10,9 @@ fn main() {
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn iterators() {
|
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!();
|
let mut fav_fruits_iterator = todo!();
|
||||||
|
|
||||||
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
||||||
|
|||||||
@ -10,9 +10,9 @@ fn main() {
|
|||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn iterators() {
|
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();
|
let mut fav_fruits_iterator = my_fav_fruits.iter();
|
||||||
|
|
||||||
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user