From cb79be921d54b2a631c50d78df43bed0988a8f62 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:32:38 +0100 Subject: [PATCH 01/16] reordered smart pointer exercises Switched rc and arc so rc comes first, since arc is, like the name implies, atomic rc. This gives the exercises a more logical progression. Moved all smart pointer exercises (box, rc, arc, cow) under threads into their own section. Threads are used in the smart pointer exercises, so they should be introduced first. --- info.toml | 122 +++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/info.toml b/info.toml index 8356f6a..7512aee 100644 --- a/info.toml +++ b/info.toml @@ -895,66 +895,6 @@ The fold method can be useful in the count_collection_iterator function. For a further challenge, consult the documentation for Iterator to find a different method that could make your code more compact than using fold.""" -[[exercises]] -name = "box1" -path = "exercises/standard_library_types/box1.rs" -mode = "test" -hint = """ -Step 1 -The compiler's message should help: since we cannot store the value of the actual type -when working with recursive types, we need to store a reference (pointer) to its value. -We should, therefore, place our `List` inside a `Box`. More details in the book here: -https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes - -Step 2 -Creating an empty list should be fairly straightforward (hint: peek at the assertions). -For a non-empty list keep in mind that we want to use our Cons "list builder". -Although the current list is one of integers (i32), feel free to change the definition -and try other types! -""" - -[[exercises]] -name = "arc1" -path = "exercises/standard_library_types/arc1.rs" -mode = "compile" -hint = """ -Make `shared_numbers` be an `Arc` from the numbers vector. Then, in order -to avoid creating a copy of `numbers`, you'll need to create `child_numbers` -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. - -This is a simple exercise if you understand the underlying concepts, but if this -is too much of a struggle, consider reading through all of Chapter 16 in the book: -https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html -""" - -[[exercises]] -name = "rc1" -path = "exercises/standard_library_types/rc1.rs" -mode = "compile" -hint = """ -This is a straightforward exercise to use the Rc type. Each Planet has -ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun. -After using drop() to move the Planets out of scope individually, the reference count goes down. -In the end the sun only has one reference again, to itself. See more at: -https://doc.rust-lang.org/book/ch15-04-rc.html - -* Unfortunately Pluto is no longer considered a planet :( -""" - -[[exercises]] -name = "cow1" -path = "exercises/standard_library_types/cow1.rs" -mode = "compile" -hint = """ -Since the vector is already owned, the `Cow` type doesn't need to clone it. - -Checkout https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation -on the `Cow` type. -""" - # THREADS [[exercises]] @@ -1016,6 +956,68 @@ of the original sending end. See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. """ +# SMART POINTERS + +[[exercises]] +name = "box1" +path = "exercises/standard_library_types/box1.rs" +mode = "test" +hint = """ +Step 1 +The compiler's message should help: since we cannot store the value of the actual type +when working with recursive types, we need to store a reference (pointer) to its value. +We should, therefore, place our `List` inside a `Box`. More details in the book here: +https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes + +Step 2 +Creating an empty list should be fairly straightforward (hint: peek at the assertions). +For a non-empty list keep in mind that we want to use our Cons "list builder". +Although the current list is one of integers (i32), feel free to change the definition +and try other types! +""" + +[[exercises]] +name = "rc1" +path = "exercises/standard_library_types/rc1.rs" +mode = "compile" +hint = """ +This is a straightforward exercise to use the Rc type. Each Planet has +ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun. +After using drop() to move the Planets out of scope individually, the reference count goes down. +In the end the sun only has one reference again, to itself. See more at: +https://doc.rust-lang.org/book/ch15-04-rc.html + +* Unfortunately Pluto is no longer considered a planet :( +""" + +[[exercises]] +name = "arc1" +path = "exercises/standard_library_types/arc1.rs" +mode = "compile" +hint = """ +Make `shared_numbers` be an `Arc` from the numbers vector. Then, in order +to avoid creating a copy of `numbers`, you'll need to create `child_numbers` +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. + +This is a simple exercise if you understand the underlying concepts, but if this +is too much of a struggle, consider reading through all of Chapter 16 in the book: +https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html +""" + +[[exercises]] +name = "cow1" +path = "exercises/standard_library_types/cow1.rs" +mode = "compile" +hint = """ +Since the vector is already owned, the `Cow` type doesn't need to clone it. + +Checkout https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation +on the `Cow` type. +""" + # MACROS [[exercises]] From 05592acf4053262c7cffe824076322da8b13e6e2 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:44:47 +0100 Subject: [PATCH 02/16] move arc to smart_pointers --- exercises/{standard_library_types => smart_pointers}/arc1.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => smart_pointers}/arc1.rs (100%) diff --git a/exercises/standard_library_types/arc1.rs b/exercises/smart_pointers/arc1.rs similarity index 100% rename from exercises/standard_library_types/arc1.rs rename to exercises/smart_pointers/arc1.rs From c3bab88fda6311b34bc3f8091c2e3cf442148d6f Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:51:27 +0100 Subject: [PATCH 03/16] moved box to smart_pointers --- exercises/{standard_library_types => smart_pointers}/box1.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => smart_pointers}/box1.rs (100%) diff --git a/exercises/standard_library_types/box1.rs b/exercises/smart_pointers/box1.rs similarity index 100% rename from exercises/standard_library_types/box1.rs rename to exercises/smart_pointers/box1.rs From e8c4aab643062da2a44b764198a5077cc1bd97a0 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:52:05 +0100 Subject: [PATCH 04/16] moved cow to smart_pointers --- exercises/{standard_library_types => smart_pointers}/cow1.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => smart_pointers}/cow1.rs (100%) diff --git a/exercises/standard_library_types/cow1.rs b/exercises/smart_pointers/cow1.rs similarity index 100% rename from exercises/standard_library_types/cow1.rs rename to exercises/smart_pointers/cow1.rs From a8fd315e099e4b5c24b450eb6ba6ec3cccd96854 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:52:47 +0100 Subject: [PATCH 05/16] moved rc to smart_pointers --- exercises/{standard_library_types => smart_pointers}/rc1.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => smart_pointers}/rc1.rs (100%) diff --git a/exercises/standard_library_types/rc1.rs b/exercises/smart_pointers/rc1.rs similarity index 100% rename from exercises/standard_library_types/rc1.rs rename to exercises/smart_pointers/rc1.rs From a0c5a892d3f1a5b4fa1d2bba41fb1dca145460f3 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:58:04 +0100 Subject: [PATCH 06/16] refactoring standard_library_types as iterators --- exercises/iterators/README.md | 8 ++++++++ exercises/standard_library_types/README.md | 10 ---------- 2 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 exercises/iterators/README.md delete mode 100644 exercises/standard_library_types/README.md diff --git a/exercises/iterators/README.md b/exercises/iterators/README.md new file mode 100644 index 0000000..0e8b671 --- /dev/null +++ b/exercises/iterators/README.md @@ -0,0 +1,8 @@ +# Iterators + +This section will teach you about Iterators. + +## Further information + +- [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) +- [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/) diff --git a/exercises/standard_library_types/README.md b/exercises/standard_library_types/README.md deleted file mode 100644 index 809d61f..0000000 --- a/exercises/standard_library_types/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Standard library types - -This section will teach you about Box, Shared-State Concurrency and Iterators. - -## Further information - -- [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html) -- [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) -- [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) -- [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/) From e9dc52c2d3abb60c532634ffbda7f435b4c3d140 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:58:57 +0100 Subject: [PATCH 07/16] moved iterator exercises --- exercises/{standard_library_types => iterators}/iterators1.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => iterators}/iterators1.rs (100%) diff --git a/exercises/standard_library_types/iterators1.rs b/exercises/iterators/iterators1.rs similarity index 100% rename from exercises/standard_library_types/iterators1.rs rename to exercises/iterators/iterators1.rs From 5b0d587c223cff097d824fbd5f8a5003f88036a0 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 01:59:35 +0100 Subject: [PATCH 08/16] moved iterator exercises --- exercises/{standard_library_types => iterators}/iterators2.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => iterators}/iterators2.rs (100%) diff --git a/exercises/standard_library_types/iterators2.rs b/exercises/iterators/iterators2.rs similarity index 100% rename from exercises/standard_library_types/iterators2.rs rename to exercises/iterators/iterators2.rs From 0f02a9b9af80e8b62709d2c50b0fcdf5f7478ea7 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:00:36 +0100 Subject: [PATCH 09/16] moved iterator exercises --- exercises/{standard_library_types => iterators}/iterators3.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => iterators}/iterators3.rs (100%) diff --git a/exercises/standard_library_types/iterators3.rs b/exercises/iterators/iterators3.rs similarity index 100% rename from exercises/standard_library_types/iterators3.rs rename to exercises/iterators/iterators3.rs From e3e298cfa21f671f32280f576c3092c62dc81b2a Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:02:15 +0100 Subject: [PATCH 10/16] moved iterator exercises --- exercises/{standard_library_types => iterators}/iterators4.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => iterators}/iterators4.rs (100%) diff --git a/exercises/standard_library_types/iterators4.rs b/exercises/iterators/iterators4.rs similarity index 100% rename from exercises/standard_library_types/iterators4.rs rename to exercises/iterators/iterators4.rs From 8405a61b07583e6d09b8811c253a8e83aa972c46 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:02:49 +0100 Subject: [PATCH 11/16] moved iterator exercises --- exercises/{standard_library_types => iterators}/iterators5.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercises/{standard_library_types => iterators}/iterators5.rs (100%) diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/iterators/iterators5.rs similarity index 100% rename from exercises/standard_library_types/iterators5.rs rename to exercises/iterators/iterators5.rs From 3fad2a9c8364c6994fa5de0ed58612ddceaf2f25 Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:17:23 +0100 Subject: [PATCH 12/16] gave smart_pointers its own README.md --- exercises/smart_pointers/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 exercises/smart_pointers/README.md diff --git a/exercises/smart_pointers/README.md b/exercises/smart_pointers/README.md new file mode 100644 index 0000000..3893e78 --- /dev/null +++ b/exercises/smart_pointers/README.md @@ -0,0 +1,11 @@ +## Smart Pointers +In Rust, smart pointers are variables that contain an address in memory and reference some other data, but they also have additional metadata and capabilities. +Smart pointers in Rust often own the data they point to, while references only borrow data. + +## Further Information + +- [Smart Pointers](https://doc.rust-lang.org/book/ch15-00-smart-pointers.html) +- [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html) +- [Rc\, the Reference Counted Smart Pointer](https://doc.rust-lang.org/book/ch15-04-rc.html) +- [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) +- [Cow Documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html) From 66eaaf7b6e5f7a5fe0ec0472c7ef9610b332bb2f Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:17:53 +0100 Subject: [PATCH 13/16] fixed formatting --- exercises/smart_pointers/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/smart_pointers/README.md b/exercises/smart_pointers/README.md index 3893e78..c517ae3 100644 --- a/exercises/smart_pointers/README.md +++ b/exercises/smart_pointers/README.md @@ -1,4 +1,4 @@ -## Smart Pointers +# Smart Pointers In Rust, smart pointers are variables that contain an address in memory and reference some other data, but they also have additional metadata and capabilities. Smart pointers in Rust often own the data they point to, while references only borrow data. From b2b6e6900fbe8b63a7d965240715ad56fa81403a Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:29:45 +0100 Subject: [PATCH 14/16] reformatted exercise->chapter mapping Added and removed rows according to changes to exercise order and grouping. --- exercises/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exercises/README.md b/exercises/README.md index e52137c..26fcdf8 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -7,7 +7,7 @@ | if | §3.5 | | primitive_types | §3.2, §4.3 | | vecs | §8.1 | -| move_semantics | §4.1, §4.2 | +| move_semantics | §4.1-2 | | structs | §5.1, §5.3 | | enums | §6, §18.3 | | strings | §8.2 | @@ -19,8 +19,9 @@ | traits | §10.2 | | tests | §11.1 | | lifetimes | §10.3 | -| standard_library_types | §13.2, §15.1, §16.3 | -| threads | §16.1, §16.2, §16.3 | +| iterators | §13.2-4 | +| threads | §16.1-3 | +| smart_pointers | §15, §16.3 | | macros | §19.6 | | clippy | n/a | | conversions | n/a | From 9860976af92ea9578980587b57f992073f6ff5ea Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:34:58 +0100 Subject: [PATCH 15/16] added existing chapter for clippy to mapping It's real! https://doc.rust-lang.org/book/appendix-04-useful-development-tools.html --- exercises/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/README.md b/exercises/README.md index 26fcdf8..c7effa9 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -23,5 +23,5 @@ | threads | §16.1-3 | | smart_pointers | §15, §16.3 | | macros | §19.6 | -| clippy | n/a | +| clippy | §21.4 | | conversions | n/a | From a5429d59f9495535f5113a4236905d86df1657ff Mon Sep 17 00:00:00 2001 From: seporterfield <107010978+seporterfield@users.noreply.github.com> Date: Sun, 1 Jan 2023 02:46:40 +0100 Subject: [PATCH 16/16] updated file paths for iterators, smart_pointers --- info.toml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/info.toml b/info.toml index 7512aee..1135c91 100644 --- a/info.toml +++ b/info.toml @@ -809,7 +809,7 @@ If you use a lifetime annotation in a struct's fields, where else does it need t [[exercises]] name = "iterators1" -path = "exercises/standard_library_types/iterators1.rs" +path = "exercises/iterators/iterators1.rs" mode = "compile" hint = """ Step 1: @@ -826,7 +826,7 @@ https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. [[exercises]] name = "iterators2" -path = "exercises/standard_library_types/iterators2.rs" +path = "exercises/iterators/iterators2.rs" mode = "test" hint = """ Step 1 @@ -847,7 +847,7 @@ and very general. Rust just needs to know the desired type.""" [[exercises]] name = "iterators3" -path = "exercises/standard_library_types/iterators3.rs" +path = "exercises/iterators/iterators3.rs" mode = "test" hint = """ The divide function needs to return the correct error when even division is not @@ -866,7 +866,7 @@ can make the solution to this exercise infinitely easier.""" [[exercises]] name = "iterators4" -path = "exercises/standard_library_types/iterators4.rs" +path = "exercises/iterators/iterators4.rs" mode = "test" hint = """ In an imperative language, you might write a for loop that updates @@ -878,7 +878,7 @@ Hint 2: Check out the `fold` and `rfold` methods!""" [[exercises]] name = "iterators5" -path = "exercises/standard_library_types/iterators5.rs" +path = "exercises/iterators/iterators5.rs" mode = "test" hint = """ The documentation for the std::iter::Iterator trait contains numerous methods @@ -960,7 +960,7 @@ See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. [[exercises]] name = "box1" -path = "exercises/standard_library_types/box1.rs" +path = "exercises/smart_pointers/box1.rs" mode = "test" hint = """ Step 1 @@ -978,7 +978,7 @@ and try other types! [[exercises]] name = "rc1" -path = "exercises/standard_library_types/rc1.rs" +path = "exercises/smart_pointers/rc1.rs" mode = "compile" hint = """ This is a straightforward exercise to use the Rc type. Each Planet has @@ -992,7 +992,7 @@ https://doc.rust-lang.org/book/ch15-04-rc.html [[exercises]] name = "arc1" -path = "exercises/standard_library_types/arc1.rs" +path = "exercises/smart_pointers/arc1.rs" mode = "compile" hint = """ Make `shared_numbers` be an `Arc` from the numbers vector. Then, in order @@ -1009,7 +1009,7 @@ https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html [[exercises]] name = "cow1" -path = "exercises/standard_library_types/cow1.rs" +path = "exercises/smart_pointers/cow1.rs" mode = "compile" hint = """ Since the vector is already owned, the `Cow` type doesn't need to clone it.