From 9642f5a3f686270a4f8f6ba969919ddbbc4f7fdd Mon Sep 17 00:00:00 2001 From: Mukund Bhudia Date: Tue, 4 Aug 2020 12:57:01 +0100 Subject: [PATCH 1/2] feat: Added iterators1.rs exercise --- exercises/standard_library_types/README.md | 2 -- .../standard_library_types/iterators1.rs | 24 +++++++++++++++++++ info.toml | 21 ++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 exercises/standard_library_types/iterators1.rs diff --git a/exercises/standard_library_types/README.md b/exercises/standard_library_types/README.md index 36b30c1..8b53dd8 100644 --- a/exercises/standard_library_types/README.md +++ b/exercises/standard_library_types/README.md @@ -3,5 +3,3 @@ For the Box exercise check out the chapter [Using Box to Point to Data on the He 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. 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/). -Do not adjust your monitors-- iterators1.rs is indeed missing. Iterators is a challenging topic, so we're leaving space for a simpler exercise! - diff --git a/exercises/standard_library_types/iterators1.rs b/exercises/standard_library_types/iterators1.rs new file mode 100644 index 0000000..3fd519d --- /dev/null +++ b/exercises/standard_library_types/iterators1.rs @@ -0,0 +1,24 @@ +// iterators1.rs +// +// Make me compile by filling in the `???`s +// +// When performing operations on elements within a collection, iterators are essential. +// This module helps you get familiar with the structure of using an iterator and +// how to go through elements within an iterable collection. +// +// Execute `rustlings hint iterators1` for hints :D + +// I AM NOT DONE + +fn main () { + let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"]; + + let mut my_iterable_fav_fruits = ???; // TODO: Step 1 + + assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana")); + assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2 + assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado")); + assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2.1 + assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry")); + assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3 +} diff --git a/info.toml b/info.toml index 46e353f..23f92bf 100644 --- a/info.toml +++ b/info.toml @@ -644,6 +644,27 @@ inside the loop but still in the main thread. `child_numbers` should be a clone of the Arc of the numbers instead of a thread-local copy of the numbers.""" +[[exercises]] +name = "iterators1" +path = "exercises/standard_library_types/iterators1.rs" +mode = "compile" +hint = """ +Step 1: +We need to apply something to the collection `my_fav_fruits` before we start to go through +it. What could that be? Take a look at the struct definition for a vector for inspiration: +https://doc.rust-lang.org/std/vec/struct.Vec.html. + + +Step 2 & step 2.1: +Very similar to the lines above an below. You've got this! + + +Step 3: +An iterator goes through all elements in a collection, but what if we've run out of +elements? What should we expect here? If you're stuck, take a look at +https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. +""" + [[exercises]] name = "iterators2" path = "exercises/standard_library_types/iterators2.rs" From 8ff5fde88edb8f24253d7dc894501473cf701dbc Mon Sep 17 00:00:00 2001 From: Mukund Bhudia Date: Fri, 18 Sep 2020 10:40:11 +0100 Subject: [PATCH 2/2] Update info.toml for typo fix Co-authored-by: Andrew Marquez --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 23f92bf..d800720 100644 --- a/info.toml +++ b/info.toml @@ -656,7 +656,7 @@ https://doc.rust-lang.org/std/vec/struct.Vec.html. Step 2 & step 2.1: -Very similar to the lines above an below. You've got this! +Very similar to the lines above and below. You've got this! Step 3: