From aa9a943ddf3ae260782e73c26bcc9db60e5894b6 Mon Sep 17 00:00:00 2001 From: Ivan Nerazumov <64264529+cseltol@users.noreply.github.com> Date: Sat, 13 Mar 2021 18:45:52 +0700 Subject: [PATCH 01/61] fix(installation): first PowerShell command ExecutionPolicy to RemoteSigned command was fixed because the old command was getting denied access to change the Execution Policy property --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b958fae6..3b7ff168 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This will install Rustlings and give you access to the `rustlings` command. Run In PowerShell, set `ExecutionPolicy` to `RemoteSigned`: ```ps -Set-ExecutionPolicy RemoteSigned +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser ``` Then, you can run: From 7f0d2c2bf011838d77fc05f111aacf2b0a663f5c Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Sat, 24 Apr 2021 12:42:06 -0400 Subject: [PATCH 02/61] chore(iterators5): Minor formatting improvements. --- exercises/standard_library_types/iterators5.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index 2d97bd46..6e246b4c 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -1,5 +1,4 @@ // iterators5.rs - // Let's define a simple model to track Rustlings exercise progress. Progress // will be modelled using a hash map. The name of the exercise is the key and // the progress is the value. Two counting functions were created to count the @@ -7,8 +6,7 @@ // imperative style for loops. Recreate this counting functionality using // iterators. Only the two iterator methods (count_iterator and // count_collection_iterator) need to be modified. -// Execute `rustlings hint -// iterators5` for hints. +// Execute `rustlings hint iterators5` for hints. // // Make the code compile and the tests pass. From 650b1dee541d3ad789c4ac6d461045e7c592b396 Mon Sep 17 00:00:00 2001 From: Maarten Tibau Date: Sun, 25 Apr 2021 17:49:46 +0200 Subject: [PATCH 03/61] chore: Update quiz1.rs add explicit test for 40 --- exercises/quiz1.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 5c5c355d..2bb2c24a 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -16,8 +16,10 @@ #[test] fn verify_test() { let price1 = calculate_apple_price(35); - let price2 = calculate_apple_price(65); + let price2 = calculate_apple_price(40); + let price3 = calculate_apple_price(65); assert_eq!(70, price1); - assert_eq!(65, price2); + assert_eq!(80, price2); + assert_eq!(65, price3); } From 166a53946cf79d01f0ae670d7778f9f7221b7cba Mon Sep 17 00:00:00 2001 From: Martin HART <82845873+martinhartxyz@users.noreply.github.com> Date: Tue, 27 Apr 2021 20:22:13 +0200 Subject: [PATCH 04/61] Correct small typo in exercises/conversions/from_str.rs --- exercises/conversions/from_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 4beebacd..93a5299a 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -20,7 +20,7 @@ struct Person { // 4. Extract the first element from the split operation and use it as the name // 5. Extract the other element from the split operation and parse it into a `usize` as the age // with something like `"4".parse::()` -// 5. If while extracting the name and the age something goes wrong, an error should be returned +// 6. If while extracting the name and the age something goes wrong, an error should be returned // If everything goes well, then return a Result of a Person object impl FromStr for Person { From 86cc85295ae36948963ae52882e285d7e3e29323 Mon Sep 17 00:00:00 2001 From: Martin HART <82845873+martinhartxyz@users.noreply.github.com> Date: Tue, 27 Apr 2021 20:22:13 +0200 Subject: [PATCH 05/61] fix: Correct small typo in exercises/conversions/from_str.rs --- exercises/conversions/from_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 4beebacd..93a5299a 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -20,7 +20,7 @@ struct Person { // 4. Extract the first element from the split operation and use it as the name // 5. Extract the other element from the split operation and parse it into a `usize` as the age // with something like `"4".parse::()` -// 5. If while extracting the name and the age something goes wrong, an error should be returned +// 6. If while extracting the name and the age something goes wrong, an error should be returned // If everything goes well, then return a Result of a Person object impl FromStr for Person { From 9569c9a9e72fb0ff792437207a579930cea8f9fb Mon Sep 17 00:00:00 2001 From: Pi Delport Date: Thu, 29 Apr 2021 23:31:26 +0200 Subject: [PATCH 06/61] style(standard_library_types): stray line break --- exercises/standard_library_types/iterators5.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index 2d97bd46..d8d44537 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -7,8 +7,7 @@ // imperative style for loops. Recreate this counting functionality using // iterators. Only the two iterator methods (count_iterator and // count_collection_iterator) need to be modified. -// Execute `rustlings hint -// iterators5` for hints. +// Execute `rustlings hint iterators5` for hints. // // Make the code compile and the tests pass. From 404f3ef465f15916f3f9348190459b64d513b056 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 1 May 2021 10:12:42 +0000 Subject: [PATCH 07/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ca25bae..fede6723 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-91-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-92-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -279,6 +279,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Shao Yang Hong

๐Ÿ–‹
Brandon Macer

๐Ÿ–‹
Stoian Dan

๐Ÿ–‹ +
Pi Delport

๐Ÿ–‹ From ce40e201f0b454822074399800886068317027aa Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 1 May 2021 10:12:43 +0000 Subject: [PATCH 08/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2f209713..4627e294 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -847,6 +847,15 @@ "contributions": [ "content" ] + }, + { + "login": "PiDelport", + "name": "Pi Delport", + "avatar_url": "https://avatars.githubusercontent.com/u/630271?v=4", + "profile": "https://about.me/pjdelport", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d9b69bd1a0a7a99f2c0d80933ad2eea44c8c71b2 Mon Sep 17 00:00:00 2001 From: Juan Pablo Ramirez Date: Sun, 9 May 2021 17:58:54 -0500 Subject: [PATCH 09/61] fix: remove trailing whitespace --- exercises/structs/structs3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 8d8b4710..a80d0625 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -31,7 +31,7 @@ impl Package { } fn get_fees(&self, cents_per_gram: i32) -> ??? { - // Something goes here... + // Something goes here... } } From 31457940846b3844d78d4a4d2b074bc8d6aaf1eb Mon Sep 17 00:00:00 2001 From: Juan Pablo Ramirez Date: Tue, 11 May 2021 14:50:05 -0500 Subject: [PATCH 10/61] fix: add hints to generics1 and generics2 exercises --- exercises/generics/generics1.rs | 2 ++ exercises/generics/generics2.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index 967287ef..f93e64a0 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -1,6 +1,8 @@ // This shopping list program isn't compiling! // Use your knowledge of generics to fix it. +// Execute `rustlings hint generics1` for hints! + // I AM NOT DONE fn main() { diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 0cb59adc..1501529c 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -1,6 +1,8 @@ // This powerful wrapper provides the ability to store a positive integer value. // Rewrite it using generics so that it supports wrapping ANY type. +// Execute `rustlings hint generics2` for hints! + // I AM NOT DONE struct Wrapper { From 4d4fa77459392acd3581c6068aa8be9a02de12fc Mon Sep 17 00:00:00 2001 From: Juan Pablo Ramirez Date: Wed, 12 May 2021 10:20:07 -0500 Subject: [PATCH 11/61] fix: remove trailing whitespaces from iterators1 --- exercises/standard_library_types/iterators1.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/standard_library_types/iterators1.rs b/exercises/standard_library_types/iterators1.rs index 3fd519d6..4606ad35 100644 --- a/exercises/standard_library_types/iterators1.rs +++ b/exercises/standard_library_types/iterators1.rs @@ -1,11 +1,11 @@ // 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 +// 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 From 11d2cf0d604dee3f5023c17802d69438e69fa50e Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sat, 15 May 2021 14:01:17 -0500 Subject: [PATCH 12/61] fix(try_from_into, from_str): hints for dyn Error Add hints about how to return the correct type for functions that return `Result<_, Box`. Some feedback from Discord suggests that people run into trouble with that. --- info.toml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/info.toml b/info.toml index 82e11952..0535a77b 100644 --- a/info.toml +++ b/info.toml @@ -893,7 +893,19 @@ path = "exercises/conversions/try_from_into.rs" mode = "test" hint = """ Follow the steps provided right before the `TryFrom` implementation. -You can also use the example at https://doc.rust-lang.org/std/convert/trait.TryFrom.html""" +You can also use the example at https://doc.rust-lang.org/std/convert/trait.TryFrom.html + +You might want to look back at the exercise errorsn (or its hints) to remind +yourself about how `Box` works. + +If you're trying to return a string as an error, note that neither `str` +nor `String` implements `error::Error`. However, there is an implementation +of `From<&str>` for `Box`. This means you can use `.into()` or +the `?` operator to convert your string into the correct error type. + +If you're having trouble with using the `?` operator to convert an error string, +recall that `?` works to convert `Err(something)` into the appropriate error +type for returning from the function.""" [[exercises]] name = "as_ref_mut" @@ -909,4 +921,7 @@ mode = "test" hint = """ The implementation of FromStr should return an Ok with a Person object, or an Err with an error if the string is not valid. -This is almost like the `try_from_into` exercise.""" +This is almost like the `try_from_into` exercise. + +If you're having trouble with returning the correct error type, see the +hints for try_from_into.""" From 399ab328d8d407265c09563aa4ef4534b2503ff2 Mon Sep 17 00:00:00 2001 From: Sateesh Date: Mon, 17 May 2021 17:40:40 +0530 Subject: [PATCH 13/61] feat: Add move_semantics5 exercise. (#746) * feat: Add move_semantics5 exercise. * feat: Add option3 exercise * Address review comments. Fix typos, sentence formatting. * Remove unwanted newline. * Address review comments: make comment inline, fix format in print. --- exercises/move_semantics/move_semantics5.rs | 14 ++++++++++++++ exercises/option/option3.rs | 19 +++++++++++++++++++ info.toml | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 exercises/move_semantics/move_semantics5.rs create mode 100644 exercises/option/option3.rs diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs new file mode 100644 index 00000000..4f8128c7 --- /dev/null +++ b/exercises/move_semantics/move_semantics5.rs @@ -0,0 +1,14 @@ +// move_semantics5.rs +// Make me compile without adding any newlines or removing any of the lines. +// Execute `rustlings hint move_semantics5` for hints :) + +// I AM NOT DONE + +fn main() { + let mut x = 100; + let y = &mut x; + let z = &mut *y; + *y += 100; + *z += 1000; + assert_eq!(x, 1200); +} diff --git a/exercises/option/option3.rs b/exercises/option/option3.rs new file mode 100644 index 00000000..045d2acb --- /dev/null +++ b/exercises/option/option3.rs @@ -0,0 +1,19 @@ +// option3.rs +// Make me compile! Execute `rustlings hint option3` for hints + +// I AM NOT DONE + +struct Point { + x: i32, + y: i32, +} + +fn main() { + let y: Option = Some(Point { x: 100, y: 200 }); + + match y { + Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y), + _ => println!("no match"), + } + y; // Fix without deleting this line. +} diff --git a/info.toml b/info.toml index 0535a77b..0e9f4282 100644 --- a/info.toml +++ b/info.toml @@ -210,6 +210,17 @@ So the end goal is to: - since we're not creating a new vec in `main` anymore, we need to create a new vec in `fill_vec`, similarly to the way we did in `main`""" +[[exercises]] +name = "move_semantics5" +path = "exercises/move_semantics/move_semantics5.rs" +mode = "compile" +hint = """ +Carefully reason about the range in which each mutable reference is in +vogue. Does updating the value of referrent (x) immediately after the +mutable reference is taken helps? Read more about 'Mutable Referenes' +in the book's section References and Borrowing': +https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references.""" + # PRIMITIVE TYPES [[exercises]] @@ -578,6 +589,16 @@ For example: Some(Some(variable)) = variable2 Also see Option::flatten """ +[[exercises]] +name = "option3" +path = "exercises/option/option3.rs" +mode = "compile" +hint = """ +The compiler says a partial move happened in the `match` +statement. How can this be avoided? The compiler shows the correction +needed. After making the correction as suggested by the compiler, do +read: https://doc.rust-lang.org/std/keyword.ref.html""" + [[exercises]] name = "result1" path = "exercises/error_handling/result1.rs" From cd02abc48138f9415d1d81da86524508d501a09f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 May 2021 12:11:04 +0000 Subject: [PATCH 14/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fede6723..503cf2cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-92-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-93-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -280,6 +280,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Brandon Macer

๐Ÿ–‹
Stoian Dan

๐Ÿ–‹
Pi Delport

๐Ÿ–‹ +
Sateesh

๐Ÿ’ป ๐Ÿ–‹ From 72e615aa7ae36c0e0a7c82b3e22a33a04f579e3c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 17 May 2021 12:11:05 +0000 Subject: [PATCH 15/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4627e294..867f1d51 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -856,6 +856,16 @@ "contributions": [ "content" ] + }, + { + "login": "sateeshkumarb", + "name": "Sateesh ", + "avatar_url": "https://avatars.githubusercontent.com/u/429263?v=4", + "profile": "https://github.com/sateeshkumarb", + "contributions": [ + "code", + "content" + ] } ], "contributorsPerLine": 8, From 4c46e5e1a33478d6cdb5f2a08b62f5ee79e35dd9 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sat, 22 May 2021 21:56:14 -0500 Subject: [PATCH 16/61] chore: minor typos in move_semantics5 hints --- info.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.toml b/info.toml index 0e9f4282..d8e7dd59 100644 --- a/info.toml +++ b/info.toml @@ -216,8 +216,8 @@ path = "exercises/move_semantics/move_semantics5.rs" mode = "compile" hint = """ Carefully reason about the range in which each mutable reference is in -vogue. Does updating the value of referrent (x) immediately after the -mutable reference is taken helps? Read more about 'Mutable Referenes' +vogue. Does updating the value of referent (x) immediately after the +mutable reference is taken helps? Read more about 'Mutable References' in the book's section References and Borrowing': https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references.""" From 1b85828548f46f58b622b5e0c00f8c989f928807 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sat, 22 May 2021 22:09:58 -0500 Subject: [PATCH 17/61] fix: move_semantics5 hints Improve the hints for move_semantics5, as well as the explanatory comments in the code. Previously, it was not clear what possible changes were allowed. It seems that reordering the statements might be the intended solution. The previous comment about not "adding newlines" doesn't make sense, so treating it as "adding new lines" makes it more clear. --- exercises/move_semantics/move_semantics5.rs | 3 ++- info.toml | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index 4f8128c7..2fb7b8e8 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -1,5 +1,6 @@ // move_semantics5.rs -// Make me compile without adding any newlines or removing any of the lines. +// Make me compile without adding, removing, or changing any of the +// lines in `main()`. // Execute `rustlings hint move_semantics5` for hints :) // I AM NOT DONE diff --git a/info.toml b/info.toml index d8e7dd59..8c8f7c18 100644 --- a/info.toml +++ b/info.toml @@ -216,10 +216,14 @@ path = "exercises/move_semantics/move_semantics5.rs" mode = "compile" hint = """ Carefully reason about the range in which each mutable reference is in -vogue. Does updating the value of referent (x) immediately after the -mutable reference is taken helps? Read more about 'Mutable References' +vogue. Does it help to update the value of referent (x) immediately after +the mutable reference is taken? Read more about 'Mutable References' in the book's section References and Borrowing': -https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references.""" +https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references. + +Additional hint: +If you can't add, change, or remove any statements in `main()`, can you +reorder them in a way that lets the program compile?""" # PRIMITIVE TYPES From 91fc9e3118f4af603c9911698cc2a234725cb032 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 6 Jun 2021 17:36:44 -0500 Subject: [PATCH 18/61] fix(iterators5): derive Clone, Copy To allow more flexibility in solutions, derive `Clone` and `Copy` for `Progress`. --- exercises/standard_library_types/iterators5.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index d8d44537..765028af 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -15,7 +15,7 @@ use std::collections::HashMap; -#[derive(PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq)] enum Progress { None, Some, From 4e079fdd0829ab271508c773aa814b21d6cff32b Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 6 Jun 2021 17:39:13 -0500 Subject: [PATCH 19/61] chore(iterators5): conciseness hint --- info.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 8c8f7c18..562fe42f 100644 --- a/info.toml +++ b/info.toml @@ -788,7 +788,10 @@ test count_iterator. The collection variable in count_collection_iterator is a slice of HashMaps. It needs to be converted into an iterator in order to use the iterator methods. -The fold method can be useful in the count_collection_iterator function.""" +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.""" # THREADS From 50ab289da6b9eb19a7486c341b00048c516b88c0 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 6 Jun 2021 20:14:29 -0500 Subject: [PATCH 20/61] fix: rename result1 to errors4 Also put it in the ERROR HANDLING section where it probably belongs. --- .../error_handling/{result1.rs => errors4.rs} | 4 ++-- info.toml | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) rename exercises/error_handling/{result1.rs => errors4.rs} (88%) diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/errors4.rs similarity index 88% rename from exercises/error_handling/result1.rs rename to exercises/error_handling/errors4.rs index b978001b..0685c374 100644 --- a/exercises/error_handling/result1.rs +++ b/exercises/error_handling/errors4.rs @@ -1,5 +1,5 @@ -// result1.rs -// Make this test pass! Execute `rustlings hint result1` for hints :) +// errors4.rs +// Make this test pass! Execute `rustlings hint errors4` for hints :) // I AM NOT DONE diff --git a/info.toml b/info.toml index 8c8f7c18..55875d7e 100644 --- a/info.toml +++ b/info.toml @@ -489,6 +489,15 @@ mode = "compile" hint = """ If other functions can return a `Result`, why shouldn't `main`?""" +[[exercises]] +name = "errors4" +path = "exercises/error_handling/errors4.rs" +mode = "test" +hint = """ +`PositiveNonzeroInteger::new` is always creating a new instance and returning an `Ok` result. +It should be doing some checking, returning an `Err` result if those checks fail, and only +returning an `Ok` result if those checks determine that everything is... okay :)""" + [[exercises]] name = "errorsn" path = "exercises/error_handling/errorsn.rs" @@ -561,7 +570,7 @@ ReportCard struct generic, but also the correct property - you will need to chan of the struct slightly too...you can do it! """ -# OPTIONS / RESULTS +# OPTIONS [[exercises]] name = "option1" @@ -603,15 +612,6 @@ statement. How can this be avoided? The compiler shows the correction needed. After making the correction as suggested by the compiler, do read: https://doc.rust-lang.org/std/keyword.ref.html""" -[[exercises]] -name = "result1" -path = "exercises/error_handling/result1.rs" -mode = "test" -hint = """ -`PositiveNonzeroInteger::new` is always creating a new instance and returning an `Ok` result. -It should be doing some checking, returning an `Err` result if those checks fail, and only -returning an `Ok` result if those checks determine that everything is... okay :)""" - # TRAITS [[exercises]] From 68d3ac567cd5c23f5593c2f4df51612bca3d09a9 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 6 Jun 2021 23:05:01 -0500 Subject: [PATCH 21/61] feature: improve error_handling exercises Add new exercises errors5 and errors6, to introduce boxed errors and custom error enums more gently. Delete errorsn, because it tried to do too much too soon. --- exercises/error_handling/errors5.rs | 53 +++++++++++++ exercises/error_handling/errors6.rs | 86 ++++++++++++++++++++ exercises/error_handling/errorsn.rs | 117 ---------------------------- info.toml | 61 ++++++++------- 4 files changed, 173 insertions(+), 144 deletions(-) create mode 100644 exercises/error_handling/errors5.rs create mode 100644 exercises/error_handling/errors6.rs delete mode 100644 exercises/error_handling/errorsn.rs diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs new file mode 100644 index 00000000..1b118000 --- /dev/null +++ b/exercises/error_handling/errors5.rs @@ -0,0 +1,53 @@ +// errors5.rs + +// This program uses a completed version of the code from errors4. +// It won't compile right now! Why? +// Execute `rustlings hint errors5` for hints! + +// I AM NOT DONE + +use std::error; +use std::fmt; +use std::num::ParseIntError; + +// TODO: update the return type of `main()` to make this compile. +fn main() -> Result<(), ParseIntError> { + let pretend_user_input = "42"; + let x: i64 = pretend_user_input.parse()?; + println!("output={:?}", PositiveNonzeroInteger::new(x)?); + Ok(()) +} + +// Don't change anything below this line. + +#[derive(PartialEq, Debug)] +struct PositiveNonzeroInteger(u64); + +#[derive(PartialEq, Debug)] +enum CreationError { + Negative, + Zero, +} + +impl PositiveNonzeroInteger { + fn new(value: i64) -> Result { + match value { + x if x < 0 => Err(CreationError::Negative), + x if x == 0 => Err(CreationError::Zero), + x => Ok(PositiveNonzeroInteger(x as u64)) + } + } +} + +// This is required so that `CreationError` can implement `error::Error`. +impl fmt::Display for CreationError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let description = match *self { + CreationError::Negative => "Number is negative", + CreationError::Zero => "Number is zero", + }; + f.write_str(description) + } +} + +impl error::Error for CreationError {} diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs new file mode 100644 index 00000000..cee72504 --- /dev/null +++ b/exercises/error_handling/errors6.rs @@ -0,0 +1,86 @@ +// errors6.rs + +// Using catch-all error types like `Box` isn't recommended +// for library code, where callers might want to make decisions based on the +// error content, instead of printing it out or propagating it further. Here, +// we define a custom error type to make it possible for callers to decide +// what to do next when our function returns an error. + +// Make these tests pass! Execute `rustlings hint errors6` for hints :) + +// I AM NOT DONE + +// This is a custom error type that we will be using in `parse_pos_nonzero()`. +#[derive(PartialEq, Debug)] +enum ParsePosNonzeroError { + CreationError, + ParseIntError +} + +fn parse_pos_nonzero(s: &str) + -> Result +{ + // TODO: change this to return an appropriate error instead of panicking + // when `parse()` returns an error. + let x: i64 = s.parse().unwrap(); + PositiveNonzeroInteger::new(x) + .or(Err(ParsePosNonzeroError::CreationError)) +} + +// Don't change anything below this line. + +#[derive(PartialEq, Debug)] +struct PositiveNonzeroInteger(u64); + +#[derive(PartialEq, Debug)] +enum CreationError { + Negative, + Zero, +} + +impl PositiveNonzeroInteger { + fn new(value: i64) -> Result { + match value { + x if x < 0 => Err(CreationError::Negative), + x if x == 0 => Err(CreationError::Zero), + x => Ok(PositiveNonzeroInteger(x as u64)) + } + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_parse_error() { + assert_eq!( + parse_pos_nonzero("not a number"), + Err(ParsePosNonzeroError::ParseIntError) + ); + } + + #[test] + fn test_negative() { + assert_eq!( + parse_pos_nonzero("-555"), + Err(ParsePosNonzeroError::CreationError) + ); + } + + #[test] + fn test_zero() { + assert_eq!( + parse_pos_nonzero("0"), + Err(ParsePosNonzeroError::CreationError) + ); + } + + #[test] + fn test_positive() { + assert_eq!( + parse_pos_nonzero("42"), + Ok(PositiveNonzeroInteger(42)) + ); + } +} diff --git a/exercises/error_handling/errorsn.rs b/exercises/error_handling/errorsn.rs deleted file mode 100644 index 5fe212bf..00000000 --- a/exercises/error_handling/errorsn.rs +++ /dev/null @@ -1,117 +0,0 @@ -// errorsn.rs -// This is a bigger error exercise than the previous ones! -// You can do it! :) -// -// Edit the `read_and_validate` function ONLY. Don't create any Errors -// that do not already exist. -// -// So many things could go wrong! -// -// - Reading from stdin could produce an io::Error -// - Parsing the input could produce a num::ParseIntError -// - Validating the input could produce a CreationError (defined below) -// -// How can we lump these errors into one general error? That is, what -// type goes where the question marks are, and how do we return -// that type from the body of read_and_validate? -// -// Execute `rustlings hint errorsn` for hints :) - -// I AM NOT DONE - -use std::error; -use std::fmt; -use std::io; - -// PositiveNonzeroInteger is a struct defined below the tests. -fn read_and_validate(b: &mut dyn io::BufRead) -> Result { - let mut line = String::new(); - b.read_line(&mut line); - let num: i64 = line.trim().parse(); - let answer = PositiveNonzeroInteger::new(num); - answer -} - -// -// Nothing below this needs to be modified -// - -// This is a test helper function that turns a &str into a BufReader. -fn test_with_str(s: &str) -> Result> { - let mut b = io::BufReader::new(s.as_bytes()); - read_and_validate(&mut b) -} - -#[test] -fn test_success() { - let x = test_with_str("42\n"); - assert_eq!(PositiveNonzeroInteger(42), x.unwrap()); -} - -#[test] -fn test_not_num() { - let x = test_with_str("eleven billion\n"); - assert!(x.is_err()); -} - -#[test] -fn test_non_positive() { - let x = test_with_str("-40\n"); - assert!(x.is_err()); -} - -#[test] -fn test_ioerror() { - struct Broken; - impl io::Read for Broken { - fn read(&mut self, _buf: &mut [u8]) -> io::Result { - Err(io::Error::new(io::ErrorKind::BrokenPipe, "uh-oh!")) - } - } - let mut b = io::BufReader::new(Broken); - assert!(read_and_validate(&mut b).is_err()); - assert_eq!("uh-oh!", read_and_validate(&mut b).unwrap_err().to_string()); -} - -#[derive(PartialEq, Debug)] -struct PositiveNonzeroInteger(u64); - -impl PositiveNonzeroInteger { - fn new(value: i64) -> Result { - if value == 0 { - Err(CreationError::Zero) - } else if value < 0 { - Err(CreationError::Negative) - } else { - Ok(PositiveNonzeroInteger(value as u64)) - } - } -} - -#[test] -fn test_positive_nonzero_integer_creation() { - assert!(PositiveNonzeroInteger::new(10).is_ok()); - assert_eq!( - Err(CreationError::Negative), - PositiveNonzeroInteger::new(-10) - ); - assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); -} - -#[derive(PartialEq, Debug)] -enum CreationError { - Negative, - Zero, -} - -impl fmt::Display for CreationError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let description = match *self { - CreationError::Negative => "Number is negative", - CreationError::Zero => "Number is zero", - }; - f.write_str(description) - } -} - -impl error::Error for CreationError {} diff --git a/info.toml b/info.toml index 55875d7e..63eb78b0 100644 --- a/info.toml +++ b/info.toml @@ -499,42 +499,49 @@ It should be doing some checking, returning an `Err` result if those checks fail returning an `Ok` result if those checks determine that everything is... okay :)""" [[exercises]] -name = "errorsn" -path = "exercises/error_handling/errorsn.rs" -mode = "test" +name = "errors5" +path = "exercises/error_handling/errors5.rs" +mode = "compile" hint = """ -First hint: To figure out what type should go where the ??? is, take a look -at the test helper function `test_with_str`, since it returns whatever -`read_and_validate` returns and `test_with_str` has its signature fully -specified. - - -Next hint: There are three places in `read_and_validate` that we call a -function that returns a `Result` (that is, the functions might fail). -Apply the `?` operator on those calls so that we return immediately from -`read_and_validate` if those function calls fail. - +Hint: There are two different possible `Result` types produced within +`main()`, which are propagated using `?` operators. How do we declare a +return type from `main()` that allows both? Another hint: under the hood, the `?` operator calls `From::from` -on the error value to convert it to a boxed trait object, a Box, -which is polymorphic-- that means that lots of different kinds of errors -can be returned from the same function because all errors act the same -since they all implement the `error::Error` trait. +on the error value to convert it to a boxed trait object, a +`Box`, which is polymorphic-- that means that lots of +different kinds of errors can be returned from the same function because +all errors act the same since they all implement the `error::Error` trait. Check out this section of the book: https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator +This exercise uses some concepts that we won't get to until later in the +course, like `Box` and the `From` trait. It's not important to understand +them in detail right now, but you can read ahead if you like. -Another another hint: Note that because the `?` operator returns -the *unwrapped* value in the `Ok` case, if we want to return a `Result` from -`read_and_validate` for *its* success case, we'll have to rewrap a value -that we got from the return value of a `?`ed call in an `Ok`-- this will -look like `Ok(something)`. +Read more about boxing errors: +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html +Read more about using the `?` operator with boxed errors: +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html +""" -Another another another hint: `Result`s must be "used", that is, you'll -get a warning if you don't handle a `Result` that you get in your -function. Read more about that in the `std::result` module docs: -https://doc.rust-lang.org/std/result/#results-must-be-used""" +[[exercises]] +name = "errors6" +path = "exercises/error_handling/errors6.rs" +mode = "test" +hint = """ +This exercise uses a completed version of `PositiveNonzeroInteger` from +the errors4. + +Below the TODO line, there is an example of using the `.or()` method +on a `Result` to transform one type of error into another. Try using +something similar on the `Result` from `parse()`. You might use the `?` +operator to return early from the function, or you might use a `match` +expression, or maybe there's another way! + +Read more about `.or()` in the `std::result` documentation: +https://doc.rust-lang.org/std/result/enum.Result.html#method.or""" # Generics From 48ffcbd2c4cc4d936c2c7480019190f179813cc5 Mon Sep 17 00:00:00 2001 From: ZC Date: Mon, 7 Jun 2021 18:22:55 +0800 Subject: [PATCH 22/61] fix(variables5): confine the answer further let mut number = 3; can lead to a correct answer, so the comment helps to direct the users to the intended answer. --- exercises/variables/variables5.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index da37ae99..175eebb3 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -4,7 +4,7 @@ // I AM NOT DONE fn main() { - let number = "T-H-R-E-E"; + let number = "T-H-R-E-E"; // don't change this line println!("Spell a Number : {}", number); number = 3; println!("Number plus two is : {}", number + 2); From b7ddd09fab97fc96f032bc8c0b9e1a64e5ffbcdd Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Wed, 9 Jun 2021 18:13:57 -0500 Subject: [PATCH 23/61] address review feedback Adjust error text and naming to conform with best practices. Use `map_err()` instead of `or()`. Wrap lower-level errors instead of ignoring their details. Also, don't "cheat" by bypassing the `new()` function in tests. Fix a dangling reference in the try_from_into hints. --- exercises/error_handling/errors5.rs | 4 ++-- exercises/error_handling/errors6.rs | 33 ++++++++++++++++++----------- info.toml | 21 ++++++++++-------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 1b118000..365a8691 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -43,8 +43,8 @@ impl PositiveNonzeroInteger { impl fmt::Display for CreationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let description = match *self { - CreationError::Negative => "Number is negative", - CreationError::Zero => "Number is zero", + CreationError::Negative => "number is negative", + CreationError::Zero => "number is zero", }; f.write_str(description) } diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index cee72504..0f6b27a6 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -10,11 +10,20 @@ // I AM NOT DONE +use std::num::ParseIntError; + // This is a custom error type that we will be using in `parse_pos_nonzero()`. #[derive(PartialEq, Debug)] enum ParsePosNonzeroError { - CreationError, - ParseIntError + Creation(CreationError), + ParseInt(ParseIntError) +} + +impl ParsePosNonzeroError { + fn from_creation(err: CreationError) -> ParsePosNonzeroError { + ParsePosNonzeroError::Creation(err) + } + // TODO: add another error conversion function here. } fn parse_pos_nonzero(s: &str) @@ -24,7 +33,7 @@ fn parse_pos_nonzero(s: &str) // when `parse()` returns an error. let x: i64 = s.parse().unwrap(); PositiveNonzeroInteger::new(x) - .or(Err(ParsePosNonzeroError::CreationError)) + .map_err(ParsePosNonzeroError::from_creation) } // Don't change anything below this line. @@ -54,17 +63,18 @@ mod test { #[test] fn test_parse_error() { - assert_eq!( + // We can't construct a ParseIntError, so we have to pattern match. + assert!(matches!( parse_pos_nonzero("not a number"), - Err(ParsePosNonzeroError::ParseIntError) - ); + Err(ParsePosNonzeroError::ParseInt(_)) + )); } #[test] fn test_negative() { assert_eq!( parse_pos_nonzero("-555"), - Err(ParsePosNonzeroError::CreationError) + Err(ParsePosNonzeroError::Creation(CreationError::Negative)) ); } @@ -72,15 +82,14 @@ mod test { fn test_zero() { assert_eq!( parse_pos_nonzero("0"), - Err(ParsePosNonzeroError::CreationError) + Err(ParsePosNonzeroError::Creation(CreationError::Zero)) ); } #[test] fn test_positive() { - assert_eq!( - parse_pos_nonzero("42"), - Ok(PositiveNonzeroInteger(42)) - ); + let x = PositiveNonzeroInteger::new(42); + assert!(x.is_ok()); + assert_eq!(parse_pos_nonzero("42"), Ok(x.unwrap())); } } diff --git a/info.toml b/info.toml index 63eb78b0..76950373 100644 --- a/info.toml +++ b/info.toml @@ -532,16 +532,19 @@ path = "exercises/error_handling/errors6.rs" mode = "test" hint = """ This exercise uses a completed version of `PositiveNonzeroInteger` from -the errors4. +errors4. -Below the TODO line, there is an example of using the `.or()` method -on a `Result` to transform one type of error into another. Try using -something similar on the `Result` from `parse()`. You might use the `?` -operator to return early from the function, or you might use a `match` -expression, or maybe there's another way! +Below the line that TODO asks you to change, there is an example of using +the `map_err()` method on a `Result` to transform one type of error into +another. Try using something similar on the `Result` from `parse()`. You +might use the `?` operator to return early from the function, or you might +use a `match` expression, or maybe there's another way! -Read more about `.or()` in the `std::result` documentation: -https://doc.rust-lang.org/std/result/enum.Result.html#method.or""" +You can create another function inside `impl ParsePosNonzeroError` to use +with `map_err()`. + +Read more about `map_err()` in the `std::result` documentation: +https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err""" # Generics @@ -927,7 +930,7 @@ hint = """ Follow the steps provided right before the `TryFrom` implementation. You can also use the example at https://doc.rust-lang.org/std/convert/trait.TryFrom.html -You might want to look back at the exercise errorsn (or its hints) to remind +You might want to look back at the exercise errors5 (or its hints) to remind yourself about how `Box` works. If you're trying to return a string as an error, note that neither `str` From 75788b1148d054e24b019c6efa47662eaf88ce74 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 24 Jun 2021 12:10:23 +0000 Subject: [PATCH 24/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 503cf2cf..07e7c700 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-93-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-94-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -281,6 +281,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Stoian Dan

๐Ÿ–‹
Pi Delport

๐Ÿ–‹
Sateesh

๐Ÿ’ป ๐Ÿ–‹ +
ZC

๐Ÿ–‹ From 73777980f1108f9362ddcf8211f0a8e9918cf996 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 24 Jun 2021 12:10:24 +0000 Subject: [PATCH 25/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 867f1d51..4e2f1efa 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -866,6 +866,15 @@ "code", "content" ] + }, + { + "login": "kayuapi", + "name": "ZC", + "avatar_url": "https://avatars.githubusercontent.com/u/10304328?v=4", + "profile": "https://github.com/kayuapi", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d91044f3a24f65e27321d544a9ff7895919fa63e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 24 Jun 2021 12:17:31 +0000 Subject: [PATCH 26/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07e7c700..2f21b990 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-94-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-95-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -282,6 +282,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pi Delport

๐Ÿ–‹
Sateesh

๐Ÿ’ป ๐Ÿ–‹
ZC

๐Ÿ–‹ +
hyperparabolic

๐Ÿ’ป From fadade85920268fa37092ba42adb0855d82478cf Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 24 Jun 2021 12:17:32 +0000 Subject: [PATCH 27/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4e2f1efa..e3ddb19a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -875,6 +875,15 @@ "contributions": [ "content" ] + }, + { + "login": "hyperparabolic", + "name": "hyperparabolic", + "avatar_url": "https://avatars.githubusercontent.com/u/12348474?v=4", + "profile": "https://github.com/hyperparabolic", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 3a4433d5a2961e3f3e613bd67459579fbc6277fa Mon Sep 17 00:00:00 2001 From: arlecchino Date: Mon, 28 Jun 2021 17:08:53 +0200 Subject: [PATCH 28/61] docs: Faster git clone command Clone only release tag without history --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f21b990..2aa54e04 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ When you get a permission denied message then you have to exclude the directory ## Manually -Basically: Clone the repository, checkout to the latest tag, run `cargo install`. +Basically: Clone the repository at the latest tag, run `cargo install`. ```bash -git clone https://github.com/rust-lang/rustlings +# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 4.4.0) +git clone -b 4.4.0 --depth 1 https://github.com/rust-lang/rustlings cd rustlings -git checkout tags/4.4.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) cargo install --force --path . ``` From 34ea029df8cb0af90524b9158990a56d6beb3d10 Mon Sep 17 00:00:00 2001 From: arlecchino Date: Tue, 29 Jun 2021 12:03:18 +0200 Subject: [PATCH 29/61] chore: Update hint of iterators3 `collect()` needs some hint for standard_library_types/iterators3 exercise with doc link for understanding different return types via `FromIterator`. --- info.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index ab4dc933..dedc65db 100644 --- a/info.toml +++ b/info.toml @@ -772,7 +772,10 @@ The division_results variable needs to be collected into a collection type. The result_with_list function needs to return a single Result where the success case is a vector of integers and the failure case is a DivisionError. -The list_of_results function needs to return a vector of results.""" +The list_of_results function needs to return a vector of results. + +See https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect how +the `FromIterator` trait is used in `collect()`.""" [[exercises]] name = "iterators4" From 2e05606edca43baeeed88c693b9041442362c148 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Jun 2021 10:46:40 +0000 Subject: [PATCH 30/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2aa54e04..ecb8bde7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-95-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-96-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -283,6 +283,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Sateesh

๐Ÿ’ป ๐Ÿ–‹
ZC

๐Ÿ–‹
hyperparabolic

๐Ÿ’ป +
arlecchino

๐Ÿ“– From 3b4514b686b15949112a50f6ec49c79e08dcae38 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Jun 2021 10:46:41 +0000 Subject: [PATCH 31/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index e3ddb19a..285584b2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -884,6 +884,15 @@ "contributions": [ "code" ] + }, + { + "login": "kolbma", + "name": "arlecchino", + "avatar_url": "https://avatars.githubusercontent.com/u/5228369?v=4", + "profile": "https://www.net4visions.at", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From a4a10987667ed5094763101fb885c9efc0e53bc3 Mon Sep 17 00:00:00 2001 From: arlecchino Date: Tue, 29 Jun 2021 13:41:16 +0200 Subject: [PATCH 32/61] Update info.toml Co-authored-by: marisa --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index dedc65db..e91909a6 100644 --- a/info.toml +++ b/info.toml @@ -774,7 +774,7 @@ case is a vector of integers and the failure case is a DivisionError. The list_of_results function needs to return a vector of results. -See https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect how +See https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect for how the `FromIterator` trait is used in `collect()`.""" [[exercises]] From 9bf4c5e8df576e36a1a2e9d022dae6b7d5e5f4f8 Mon Sep 17 00:00:00 2001 From: arlecchino Date: Tue, 29 Jun 2021 20:47:32 +0200 Subject: [PATCH 33/61] chore: clippy1 hint enhancement Added some explanation and links about floating point representation and to use the clippy suggestion. (fixes #390) --- info.toml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index e91909a6..afc7fdfe 100644 --- a/info.toml +++ b/info.toml @@ -902,7 +902,15 @@ name = "clippy1" path = "exercises/clippy/clippy1.rs" mode = "clippy" hint = """ -Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble""" +Not every floating point value can be represented exactly in binary values in +memory. Take a look at the description of +https://doc.rust-lang.org/stable/std/primitive.f32.html +When using the binary compare operators with floating points you won't compare +the floating point values but the binary representation in memory. This is +usually not what you would like to do. +See the suggestions of the clippy warning in compile output and use the +machine epsilon value... +https://doc.rust-lang.org/stable/std/primitive.f32.html#associatedconstant.EPSILON""" [[exercises]] name = "clippy2" From d20e413a68772cd493561f2651cf244e822b7ca5 Mon Sep 17 00:00:00 2001 From: Richthofen Date: Wed, 30 Jun 2021 03:05:49 -0700 Subject: [PATCH 34/61] feat(cli): Add "next" to run the next unsolved exercise. (#785) * Add "run next" to run the next unsolved exercise. * Fix a grammar error in the message. * Update README.md with the suggested change Co-authored-by: marisa * Update the README.md for "rustlings hint next". Co-authored-by: marisa --- README.md | 12 ++++++++++++ src/main.rs | 25 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ecb8bde7..bbaea0cf 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ In case you want to go by your own order, or want to only verify a single exerci rustlings run myExercise1 ``` +Or simply use the following command to run the next unsolved exercise in the course: + +```bash +rustlings run next +``` + In case you get stuck, you can run the following command to get a hint for your exercise: @@ -104,6 +110,12 @@ exercise: rustlings hint myExercise1 ``` +You can also get the hint for the next unsolved exercise with the following command: + +``` bash +rustlings hint next +``` + To check your progress, you can run the following command: ```bash rustlings list diff --git a/src/main.rs b/src/main.rs index a80ce88e..985fe34f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -286,13 +286,24 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { } fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise { - exercises - .iter() - .find(|e| e.name == name) - .unwrap_or_else(|| { - println!("No exercise found for '{}'!", name); - std::process::exit(1) - }) + if name.eq("next") { + exercises + .iter() + .find(|e| !e.looks_done()) + .unwrap_or_else(|| { + println!("๐ŸŽ‰ Congratulations! You have done all the exercises!"); + println!("๐Ÿ”š There are no more exercises to do next!"); + std::process::exit(1) + }) + } else { + exercises + .iter() + .find(|e| e.name == name) + .unwrap_or_else(|| { + println!("No exercise found for '{}'!", name); + std::process::exit(1) + }) + } } fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { From 1043a06124a0125a1d205180ec1c8e8e0166cf3c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 30 Jun 2021 10:06:06 +0000 Subject: [PATCH 35/61] docs: update README.md [skip ci] --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbaea0cf..db254685 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-96-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-97-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -297,6 +297,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
hyperparabolic

๐Ÿ’ป
arlecchino

๐Ÿ“– + +
Richthofen

๐Ÿ’ป + From 03dcb582e6c816cf6cb13e55a1d91485e5dfacc3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 30 Jun 2021 10:06:07 +0000 Subject: [PATCH 36/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 285584b2..c449587a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -893,6 +893,15 @@ "contributions": [ "doc" ] + }, + { + "login": "jazzplato", + "name": "Richthofen", + "avatar_url": "https://avatars.githubusercontent.com/u/7576730?v=4", + "profile": "https://richthofen.io/", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 6a10f900b4b4f599a13892ea03603bbeac059e3b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:56:56 +0000 Subject: [PATCH 37/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d70cd55d..9f8f90f4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-97-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-98-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -299,6 +299,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Richthofen

๐Ÿ’ป +
Ivan Nerazumov

๐Ÿ“– From 91d86a1de960c7efabff21e192f415592e517540 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:56:57 +0000 Subject: [PATCH 38/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c449587a..a441a6af 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -902,6 +902,15 @@ "contributions": [ "code" ] + }, + { + "login": "cseltol", + "name": "Ivan Nerazumov", + "avatar_url": "https://avatars.githubusercontent.com/u/64264529?v=4", + "profile": "https://github.com/cseltol", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From e422ab150738f578c4dc2560687a1e7214924d31 Mon Sep 17 00:00:00 2001 From: Laura Lindzey Date: Mon, 5 Jul 2021 23:07:34 -0700 Subject: [PATCH 39/61] docs: Update exercise to chapter mapping for HashMap --- exercises/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/README.md b/exercises/README.md index 0c715247..eebbd0bb 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -10,7 +10,7 @@ | structs | ยง5.1 | | enums | ยง6 | | modules | ยง7.2 | -| collections | ยง8.1 | +| collections | ยง8.1, ยง8.3 | | strings | ยง8.2 | | error_handling | ยง9 | | generics | ยง10 | From 8774e47dc34c8a7929a8b7d7504999028935ff6e Mon Sep 17 00:00:00 2001 From: lauralindzey <65185744+lauralindzey@users.noreply.github.com> Date: Tue, 6 Jul 2021 01:31:27 -0700 Subject: [PATCH 40/61] docs: Update collections README with HashMap link --- exercises/collections/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/collections/README.md b/exercises/collections/README.md index 0291bc87..b6d62acb 100644 --- a/exercises/collections/README.md +++ b/exercises/collections/README.md @@ -20,3 +20,4 @@ structures that are used very often in Rust programs: ## Further information - [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) +- [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) From b017579577dccce491a5f6fefd4515ac8f7d43bd Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:17:03 +0000 Subject: [PATCH 41/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f8f90f4..d7eef8d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-98-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -300,6 +300,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Richthofen

๐Ÿ’ป
Ivan Nerazumov

๐Ÿ“– +
lauralindzey

๐Ÿ“– From b438049c393d78fa65ea53468dc8f6093610ca8f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:17:04 +0000 Subject: [PATCH 42/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index a441a6af..fca0d0d1 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -911,6 +911,15 @@ "contributions": [ "doc" ] + }, + { + "login": "lauralindzey", + "name": "lauralindzey", + "avatar_url": "https://avatars.githubusercontent.com/u/65185744?v=4", + "profile": "https://github.com/lauralindzey", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From d876649616cc8a8dd5f539f8bc1a5434b960b1e9 Mon Sep 17 00:00:00 2001 From: Rakshit Sinha Date: Wed, 7 Jul 2021 13:18:33 -0700 Subject: [PATCH 43/61] fix(quiz1): Updated question description (#794) Co-authored-by: Rakshit Sinha --- exercises/quiz1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 2bb2c24a..3af1293d 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -5,7 +5,7 @@ // Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy // more than 40 at once, each apple only costs 1! Write a function that calculates -// the price of an order of apples given the order amount. No hints this time! +// the price of an order of apples given the quantity bought. No hints this time! // I AM NOT DONE From 23f700dc2375787fe8c79f4e191fb9e6aa3b2ef2 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:19:47 +0000 Subject: [PATCH 44/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7eef8d3..5497944d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-99-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-100-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -301,6 +301,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Richthofen

๐Ÿ’ป
Ivan Nerazumov

๐Ÿ“–
lauralindzey

๐Ÿ“– +
Rakshit Sinha

๐Ÿ–‹ From 33fa274bbfa85d817a39562b0461f8d42f1418c1 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 7 Jul 2021 20:19:48 +0000 Subject: [PATCH 45/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index fca0d0d1..85c66703 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -920,6 +920,15 @@ "contributions": [ "doc" ] + }, + { + "login": "sinharaksh1t", + "name": "Rakshit Sinha", + "avatar_url": "https://avatars.githubusercontent.com/u/28585848?v=4", + "profile": "https://github.com/sinharaksh1t", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From ba087ce64a35c93e40689d258f6dfde538b9ca22 Mon Sep 17 00:00:00 2001 From: ana Date: Wed, 7 Jul 2021 22:23:52 +0200 Subject: [PATCH 46/61] release: 4.5.0 Signed-off-by: ana --- CHANGELOG.md | 24 ++++++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 4 ++-- README.md | 4 ++-- src/main.rs | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1686bdd6..67b8cdc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ + +## 4.5.0 (2021-07-07) + + +#### Features + +* Add move_semantics5 exercise. (#746) ([399ab328](https://github.com/rust-lang/rustlings/commit/399ab328d8d407265c09563aa4ef4534b2503ff2)) +* **cli:** Add "next" to run the next unsolved exercise. (#785) ([d20e413a](https://github.com/rust-lang/rustlings/commit/d20e413a68772cd493561f2651cf244e822b7ca5)) + +#### Bug Fixes + +* rename result1 to errors4 ([50ab289d](https://github.com/rust-lang/rustlings/commit/50ab289da6b9eb19a7486c341b00048c516b88c0)) +* move_semantics5 hints ([1b858285](https://github.com/rust-lang/rustlings/commit/1b85828548f46f58b622b5e0c00f8c989f928807)) +* remove trailing whitespaces from iterators1 ([4d4fa774](https://github.com/rust-lang/rustlings/commit/4d4fa77459392acd3581c6068aa8be9a02de12fc)) +* add hints to generics1 and generics2 exercises ([31457940](https://github.com/rust-lang/rustlings/commit/31457940846b3844d78d4a4d2b074bc8d6aaf1eb)) +* remove trailing whitespace ([d9b69bd1](https://github.com/rust-lang/rustlings/commit/d9b69bd1a0a7a99f2c0d80933ad2eea44c8c71b2)) +* **installation:** first PowerShell command ([aa9a943d](https://github.com/rust-lang/rustlings/commit/aa9a943ddf3ae260782e73c26bcc9db60e5894b6)) +* **iterators5:** derive Clone, Copy ([91fc9e31](https://github.com/rust-lang/rustlings/commit/91fc9e3118f4af603c9911698cc2a234725cb032)) +* **quiz1:** Updated question description (#794) ([d8766496](https://github.com/rust-lang/rustlings/commit/d876649616cc8a8dd5f539f8bc1a5434b960b1e9)) +* **try_from_into, from_str:** hints for dyn Error ([11d2cf0d](https://github.com/rust-lang/rustlings/commit/11d2cf0d604dee3f5023c17802d69438e69fa50e)) +* **variables5:** confine the answer further ([48ffcbd2](https://github.com/rust-lang/rustlings/commit/48ffcbd2c4cc4d936c2c7480019190f179813cc5)) + + + ## 4.4.0 (2021-04-24) diff --git a/Cargo.lock b/Cargo.lock index cc8ff94a..d291c169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,7 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "rustlings" -version = "4.4.0" +version = "4.5.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 0a757040..615a09c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustlings" -version = "4.4.0" -authors = ["Marisa ", "Carol (Nichols || Goulding) "] +version = "4.5.0" +authors = ["anastasie ", "Carol (Nichols || Goulding) "] edition = "2018" [dependencies] diff --git a/README.md b/README.md index 5497944d..7313c8e1 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ When you get a permission denied message then you have to exclude the directory Basically: Clone the repository at the latest tag, run `cargo install`. ```bash -# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 4.4.0) -git clone -b 4.4.0 --depth 1 https://github.com/rust-lang/rustlings +# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 4.5.0) +git clone -b 4.5.0 --depth 1 https://github.com/rust-lang/rustlings cd rustlings cargo install --force --path . ``` diff --git a/src/main.rs b/src/main.rs index 985fe34f..c8ebc68b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.4.0"; +const VERSION: &str = "4.5.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From df25684cb79f8413915e00b5efef29369849cef1 Mon Sep 17 00:00:00 2001 From: ana Date: Thu, 29 Jul 2021 12:37:15 +0200 Subject: [PATCH 47/61] fix(move_semantics5): Clarify instructions --- exercises/move_semantics/move_semantics5.rs | 4 ++-- info.toml | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index 2fb7b8e8..5449e951 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -1,6 +1,6 @@ // move_semantics5.rs -// Make me compile without adding, removing, or changing any of the -// lines in `main()`. +// Make me compile only be reordering the lines in `main()`, but without +// adding, changing or removing any of them. // Execute `rustlings hint move_semantics5` for hints :) // I AM NOT DONE diff --git a/info.toml b/info.toml index afc7fdfe..d5008ede 100644 --- a/info.toml +++ b/info.toml @@ -220,10 +220,7 @@ vogue. Does it help to update the value of referent (x) immediately after the mutable reference is taken? Read more about 'Mutable References' in the book's section References and Borrowing': https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references. - -Additional hint: -If you can't add, change, or remove any statements in `main()`, can you -reorder them in a way that lets the program compile?""" +""" # PRIMITIVE TYPES From 03131a3d35d9842598150f9da817f7cc26e2669a Mon Sep 17 00:00:00 2001 From: Damian <54457902+dbednar230@users.noreply.github.com> Date: Tue, 24 Aug 2021 03:48:51 -0500 Subject: [PATCH 48/61] fix(quiz1): Fix inconsistent wording (#826) The second test expects the function to return 80 when there is an order of 40 apples, but the current wording implies returning 40 will pass as well --- exercises/quiz1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 3af1293d..985cd97c 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -4,7 +4,7 @@ // - Functions // Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy -// more than 40 at once, each apple only costs 1! Write a function that calculates +// 40 or more at once, each apple only costs 1! Write a function that calculates // the price of an order of apples given the quantity bought. No hints this time! // I AM NOT DONE From ba8f97f4188e516102852cf2b595774b3b0fb0bc Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 24 Aug 2021 08:49:23 +0000 Subject: [PATCH 49/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7313c8e1..6ae6979e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-100-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-101-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -302,6 +302,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Ivan Nerazumov

๐Ÿ“–
lauralindzey

๐Ÿ“–
Rakshit Sinha

๐Ÿ–‹ +
Damian

๐Ÿ–‹ From 380587f12024a4d62c254d6e1cb08e1ec488caea Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 24 Aug 2021 08:49:24 +0000 Subject: [PATCH 50/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 85c66703..22df6a56 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -929,6 +929,15 @@ "contributions": [ "content" ] + }, + { + "login": "dbednar230", + "name": "Damian", + "avatar_url": "https://avatars.githubusercontent.com/u/54457902?v=4", + "profile": "https://github.com/dbednar230", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 1cd9328a5872f1d6a95b02824e1af33a423c047a Mon Sep 17 00:00:00 2001 From: Ben Armstead Date: Tue, 24 Aug 2021 12:06:30 +0000 Subject: [PATCH 51/61] fix(cli): remove unnecessary borrows (#829) * Update dependencies * Format better and remove unnecessary borrows --- Cargo.lock | 114 ++++++++++++++++++++++++------------------------ src/exercise.rs | 2 +- src/main.rs | 2 +- src/verify.rs | 16 +++---- 4 files changed, 68 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d291c169..57b211be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,19 +1,21 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] [[package]] name = "argh" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91792f088f87cdc7a2cfb1d617fa5ea18d7f1dc22ef0e1b5f82f3157cdc522be" +checksum = "2e7317a549bc17c5278d9e72bb6e62c6aa801ac2567048e39ebc1c194249323e" dependencies = [ "argh_derive", "argh_shared", @@ -21,9 +23,9 @@ dependencies = [ [[package]] name = "argh_derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4eb0c0c120ad477412dc95a4ce31e38f2113e46bd13511253f79196ca68b067" +checksum = "60949c42375351e9442e354434b0cba2ac402c1237edf673cac3a4bf983b8d3c" dependencies = [ "argh_shared", "heck", @@ -34,9 +36,9 @@ dependencies = [ [[package]] name = "argh_shared" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "781f336cc9826dbaddb9754cb5db61e64cab4f69668bd19dcc4a0394a86f4cb1" +checksum = "8a61eb019cb8f415d162cb9f12130ee6bbe9168b7d953c17f4ad049e4051ca00" [[package]] name = "assert_cmd" @@ -69,9 +71,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cfg-if" @@ -156,9 +158,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" +checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98" dependencies = [ "cfg-if 1.0.0", "libc", @@ -218,18 +220,18 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -269,9 +271,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" dependencies = [ "cfg-if 1.0.0", ] @@ -287,9 +289,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "kernel32-sys" @@ -315,15 +317,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "a1fa8cddc8fbbee11227ef194b5317ed014b8acbf15139bd716a18ad3fe99ec5" [[package]] name = "lock_api" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" dependencies = [ "scopeguard", ] @@ -339,9 +341,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "mio" @@ -405,9 +407,9 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "notify" -version = "4.0.16" +version = "4.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2599080e87c9bd051ddb11b10074f4da7b1223298df65d4c2ec5bcf309af1533" +checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" dependencies = [ "bitflags", "filetime", @@ -466,9 +468,9 @@ dependencies = [ [[package]] name = "predicates" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" +checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df" dependencies = [ "difference", "float-cmp", @@ -485,9 +487,9 @@ checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" +checksum = "d7dd0fd014130206c9352efbdc92be592751b2b9274dff685348341082c6ea3d" dependencies = [ "predicates-core", "treeline", @@ -495,9 +497,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ "unicode-xid", ] @@ -513,18 +515,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.6" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.4.6" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", @@ -533,9 +535,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" @@ -576,18 +578,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.125" +version = "1.0.129" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +checksum = "d1f72836d2aa753853178eda473a3b9d8e4eefdaf20523b919677e6de489f8f1" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.125" +version = "1.0.129" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +checksum = "e57ae87ad533d9a56427558b516d0adac283614e347abf85b0dc0cbbf0a249f3" dependencies = [ "proc-macro2", "quote", @@ -596,9 +598,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127" dependencies = [ "itoa", "ryu", @@ -607,9 +609,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "smallvec" @@ -619,9 +621,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" +checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7" dependencies = [ "proc-macro2", "quote", @@ -630,9 +632,9 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" +checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" dependencies = [ "libc", "winapi 0.3.9", @@ -664,9 +666,9 @@ checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -676,9 +678,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "walkdir" diff --git a/src/exercise.rs b/src/exercise.rs index d934cfd3..53457ace 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -162,7 +162,7 @@ path = "{}.rs""#, if cmd.status.success() { Ok(CompiledExercise { - exercise: &self, + exercise: self, _handle: FileHandle, }) } else { diff --git a/src/main.rs b/src/main.rs index c8ebc68b..1e343478 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,7 +203,7 @@ fn main() { Subcommands::Run(subargs) => { let exercise = find_exercise(&subargs.name, &exercises); - run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); + run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); } Subcommands::Hint(subargs) => { diff --git a/src/verify.rs b/src/verify.rs index b98598a8..fd59fa51 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -14,9 +14,9 @@ pub fn verify<'a>( ) -> Result<(), &'a Exercise> { for exercise in start_at { let compile_result = match exercise.mode { - Mode::Test => compile_and_test(&exercise, RunMode::Interactive, verbose), - Mode::Compile => compile_and_run_interactively(&exercise), - Mode::Clippy => compile_only(&exercise), + Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose), + Mode::Compile => compile_and_run_interactively(exercise), + Mode::Clippy => compile_only(exercise), }; if !compile_result.unwrap_or(false) { return Err(exercise); @@ -42,11 +42,11 @@ fn compile_only(exercise: &Exercise) -> Result { progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); - let _ = compile(&exercise, &progress_bar)?; + let _ = compile(exercise, &progress_bar)?; progress_bar.finish_and_clear(); success!("Successfully compiled {}!", exercise); - Ok(prompt_for_completion(&exercise, None)) + Ok(prompt_for_completion(exercise, None)) } // Compile the given Exercise and run the resulting binary in an interactive mode @@ -55,7 +55,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); - let compilation = compile(&exercise, &progress_bar)?; + let compilation = compile(exercise, &progress_bar)?; progress_bar.set_message(format!("Running {}...", exercise).as_str()); let result = compilation.run(); @@ -73,7 +73,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { success!("Successfully ran {}!", exercise); - Ok(prompt_for_completion(&exercise, Some(output.stdout))) + Ok(prompt_for_completion(exercise, Some(output.stdout))) } // Compile the given Exercise as a test harness and display @@ -94,7 +94,7 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re } success!("Successfully tested {}", &exercise); if let RunMode::Interactive = run_mode { - Ok(prompt_for_completion(&exercise, None)) + Ok(prompt_for_completion(exercise, None)) } else { Ok(true) } From 2f0ff258b1c3780971d9b7896d8ede7848fefcdb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 24 Aug 2021 12:06:44 +0000 Subject: [PATCH 52/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ae6979e..c867258c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-101-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -303,6 +303,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
lauralindzey

๐Ÿ“–
Rakshit Sinha

๐Ÿ–‹
Damian

๐Ÿ–‹ +
Ben Armstead

๐Ÿ’ป From a64dbdcc043ae907c003ff940b43f0315283899d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 24 Aug 2021 12:06:45 +0000 Subject: [PATCH 53/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 22df6a56..7816a0b8 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -938,6 +938,15 @@ "contributions": [ "content" ] + }, + { + "login": "benarmstead", + "name": "Ben Armstead", + "avatar_url": "https://avatars.githubusercontent.com/u/70973680?v=4", + "profile": "https://benarmstead.co.uk", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 96fc3017642b1b4b224390320111c6e305c736a3 Mon Sep 17 00:00:00 2001 From: diannasoriel Date: Thu, 26 Aug 2021 10:30:18 +0200 Subject: [PATCH 54/61] chore(quiz1): revert wording --- exercises/quiz1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 985cd97c..3af1293d 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -4,7 +4,7 @@ // - Functions // Mary is buying apples. One apple usually costs 2 Rustbucks, but if you buy -// 40 or more at once, each apple only costs 1! Write a function that calculates +// more than 40 at once, each apple only costs 1! Write a function that calculates // the price of an order of apples given the quantity bought. No hints this time! // I AM NOT DONE From dfd2fab4f33d1bf59e2e5ee03123c0c9a67a9481 Mon Sep 17 00:00:00 2001 From: anuk909 <34924662+anuk909@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:41:12 +0300 Subject: [PATCH 55/61] feat(modules): update exercises, add modules3 (#822) Co-authored-by: diannasoriel --- exercises/README.md | 2 +- exercises/modules/README.md | 2 +- exercises/modules/modules1.rs | 6 ++++++ exercises/modules/modules2.rs | 8 ++++++-- exercises/modules/modules3.rs | 18 ++++++++++++++++++ info.toml | 18 +++++++++++++----- 6 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 exercises/modules/modules3.rs diff --git a/exercises/README.md b/exercises/README.md index eebbd0bb..73754db5 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -9,7 +9,7 @@ | primitive_types | ยง4.3 | | structs | ยง5.1 | | enums | ยง6 | -| modules | ยง7.2 | +| modules | ยง7 | | collections | ยง8.1, ยง8.3 | | strings | ยง8.2 | | error_handling | ยง9 | diff --git a/exercises/modules/README.md b/exercises/modules/README.md index 6582b000..3dc8a482 100644 --- a/exercises/modules/README.md +++ b/exercises/modules/README.md @@ -4,4 +4,4 @@ In this section we'll give you an introduction to Rust's module system. ## Further information -- [The Module System](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html) +- [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html) diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 812dfeef..1a2bd0dd 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -4,7 +4,13 @@ // I AM NOT DONE mod sausage_factory { + // Don't let anybody outside of this module see this! + fn get_secret_recipe() -> String { + String::from("Ginger") + } + fn make_sausage() { + get_secret_recipe(); println!("sausage!"); } } diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index fde439d1..687bb788 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -1,11 +1,15 @@ // modules2.rs +// You can bring module paths into scopes and provide new names for them with the +// 'use' and 'as' keywords. Fix these 'use' statments to make the code compile. // Make me compile! Execute `rustlings hint modules2` for hints :) // I AM NOT DONE mod delicious_snacks { - use self::fruits::PEAR as fruit; - use self::veggies::CUCUMBER as veggie; + + // TODO: Fix these use statments + use self::fruits::PEAR as ??? + use self::veggies::CUCUMBER as ??? mod fruits { pub const PEAR: &'static str = "Pear"; diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs new file mode 100644 index 00000000..8eed77df --- /dev/null +++ b/exercises/modules/modules3.rs @@ -0,0 +1,18 @@ +// modules3.rs +// You can use the 'use' keyword to bring module paths from modules from anywhere +// and especially from the Rust standard library into your scope. +// Bring SystemTime and UNIX_EPOCH +// from the std::time module. Bonus style points if you can do it with one line! +// Make me compile! Execute `rustlings hint modules3` for hints :) + +// I AM NOT DONE + +// TODO: Complete this use statement +use ??? + +fn main() { + match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()), + Err(_) => panic!("SystemTime before UNIX EPOCH!"), + } +} diff --git a/info.toml b/info.toml index d5008ede..0f68d059 100644 --- a/info.toml +++ b/info.toml @@ -362,11 +362,19 @@ name = "modules2" path = "exercises/modules/modules2.rs" mode = "compile" hint = """ -The delicious_snacks module is trying to present an external -interface (the `fruit` and `veggie` constants) that is different than -its internal structure (the `fruits` and `veggies` modules and -associated constants). It's almost there except for one keyword missing for -each constant.""" +The delicious_snacks module is trying to present an external interface that is +different than its internal structure (the `fruits` and `veggies` modules and +associated constants). Complete the `use` statemants to fit the uses in main and +find the one keyword missing for both constants.""" + +[[exercises]] +name = "modules3" +path = "exercises/modules/modules3.rs" +mode = "compile" +hint = """ +UNIX_EPOCH and SystemTime are declared in the std::time module. Add a use statement +for these two to bring them into scope. You can use nested paths or the glob +operator to bring these two in using only one line.""" # COLLECTIONS From 5423f1be29abc97a5659cac05a819a36d62182f5 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 3 Sep 2021 08:41:42 +0000 Subject: [PATCH 56/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c867258c..608bba9b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-102-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-103-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -304,6 +304,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Rakshit Sinha

๐Ÿ–‹
Damian

๐Ÿ–‹
Ben Armstead

๐Ÿ’ป +
anuk909

๐Ÿ–‹ ๐Ÿ’ป From 44d8047249bc4c32ccc1cbc5de848caea0df8c2f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 3 Sep 2021 08:41:43 +0000 Subject: [PATCH 57/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7816a0b8..03e8dd1c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -947,6 +947,16 @@ "contributions": [ "code" ] + }, + { + "login": "anuk909", + "name": "anuk909", + "avatar_url": "https://avatars.githubusercontent.com/u/34924662?v=4", + "profile": "https://github.com/anuk909", + "contributions": [ + "content", + "code" + ] } ], "contributorsPerLine": 8, From 1c3beb0a59178c950dc05fe8ee2346b017429ae0 Mon Sep 17 00:00:00 2001 From: granddaifuku <49578068+granddaifuku@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:32:39 +0900 Subject: [PATCH 58/61] fix(modules2): fix typo (#835) --- exercises/modules/modules2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index 687bb788..87f0c458 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -1,13 +1,13 @@ // modules2.rs // You can bring module paths into scopes and provide new names for them with the -// 'use' and 'as' keywords. Fix these 'use' statments to make the code compile. +// 'use' and 'as' keywords. Fix these 'use' statements to make the code compile. // Make me compile! Execute `rustlings hint modules2` for hints :) // I AM NOT DONE mod delicious_snacks { - // TODO: Fix these use statments + // TODO: Fix these use statements use self::fruits::PEAR as ??? use self::veggies::CUCUMBER as ??? From 6c41adef63d777a90bf2a80f0abb5efeb872f52b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 6 Sep 2021 14:33:03 +0000 Subject: [PATCH 59/61] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 608bba9b..e28a4815 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-103-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-104-orange.svg?style=flat-square)](#contributors-) # rustlings ๐Ÿฆ€โค๏ธ @@ -305,6 +305,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Damian

๐Ÿ–‹
Ben Armstead

๐Ÿ’ป
anuk909

๐Ÿ–‹ ๐Ÿ’ป +
granddaifuku

๐Ÿ–‹ From de22b132731bd6f9bae6d0a90707d29e9d3bc389 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 6 Sep 2021 14:33:05 +0000 Subject: [PATCH 60/61] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 03e8dd1c..5a932d94 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -957,6 +957,15 @@ "content", "code" ] + }, + { + "login": "granddaifuku", + "name": "granddaifuku", + "avatar_url": "https://avatars.githubusercontent.com/u/49578068?v=4", + "profile": "https://granddaifuku.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 6efa7d5d1554f8973346e9e15dbd5268306a2458 Mon Sep 17 00:00:00 2001 From: "joakim.kartveit" Date: Thu, 9 Sep 2021 15:53:05 +0200 Subject: [PATCH 61/61] Added ignore for .iml files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 06de8710..253f8f33 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ exercises/clippy/Cargo.toml exercises/clippy/Cargo.lock .idea .vscode +*.iml