Skip to content

Commit 0f16463

Browse files
author
fmoko
authored
Merge pull request #489 from mukundbhudia/iterators1
2 parents 3286c5e + 8ff5fde commit 0f16463

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

exercises/standard_library_types/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ For the Box exercise check out the chapter [Using Box to Point to Data on the He
33
For the Arc exercise check out the chapter [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) of the Rust Book.
44

55
For the Iterator exercise check out the chapters [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) of the Rust Book and the [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/).
6-
Do not adjust your monitors-- iterators1.rs is indeed missing. Iterators is a challenging topic, so we're leaving space for a simpler exercise!
7-
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// iterators1.rs
2+
//
3+
// Make me compile by filling in the `???`s
4+
//
5+
// When performing operations on elements within a collection, iterators are essential.
6+
// This module helps you get familiar with the structure of using an iterator and
7+
// how to go through elements within an iterable collection.
8+
//
9+
// Execute `rustlings hint iterators1` for hints :D
10+
11+
// I AM NOT DONE
12+
13+
fn main () {
14+
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
15+
16+
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
17+
18+
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
19+
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
20+
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
21+
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2.1
22+
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
23+
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
24+
}

info.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,27 @@ inside the loop but still in the main thread.
644644
`child_numbers` should be a clone of the Arc of the numbers instead of a
645645
thread-local copy of the numbers."""
646646

647+
[[exercises]]
648+
name = "iterators1"
649+
path = "exercises/standard_library_types/iterators1.rs"
650+
mode = "compile"
651+
hint = """
652+
Step 1:
653+
We need to apply something to the collection `my_fav_fruits` before we start to go through
654+
it. What could that be? Take a look at the struct definition for a vector for inspiration:
655+
https://doc.rust-lang.org/std/vec/struct.Vec.html.
656+
657+
658+
Step 2 & step 2.1:
659+
Very similar to the lines above and below. You've got this!
660+
661+
662+
Step 3:
663+
An iterator goes through all elements in a collection, but what if we've run out of
664+
elements? What should we expect here? If you're stuck, take a look at
665+
https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas.
666+
"""
667+
647668
[[exercises]]
648669
name = "iterators2"
649670
path = "exercises/standard_library_types/iterators2.rs"

0 commit comments

Comments
 (0)