mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-26 07:14:17 -05:00
Merge pull request #1313 from seporterfield/reorder-exercises
Reorder exercises
This commit is contained in:
commit
7e98f67df8
14 changed files with 91 additions and 79 deletions
|
@ -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 |
|
||||
| clippy | §21.4 |
|
||||
| conversions | n/a |
|
||||
|
|
8
exercises/iterators/README.md
Normal file
8
exercises/iterators/README.md
Normal file
|
@ -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/)
|
11
exercises/smart_pointers/README.md
Normal file
11
exercises/smart_pointers/README.md
Normal file
|
@ -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\<T\>, 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)
|
|
@ -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/)
|
132
info.toml
132
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
|
||||
|
@ -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<T> 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/smart_pointers/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/smart_pointers/rc1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
This is a straightforward exercise to use the Rc<T> 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/smart_pointers/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/smart_pointers/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]]
|
||||
|
|
Loading…
Reference in a new issue