From 9b6c629397b24b944f484f5b2bbd8144266b5695 Mon Sep 17 00:00:00 2001 From: Jacob Tinkhauser <75188781+tinkhauser@users.noreply.github.com> Date: Sun, 29 Nov 2020 01:35:14 +0000 Subject: [PATCH 001/476] fix(vec1): Have test compare every element in a and v The previous test would stop comparing elements in array a and vec v upon reaching the last element of either. This resulted in the test passing even if v did not contain all the elements in a. This change to the test fixes that bug and should only pass if all the elements in a and v are present and equal. --- exercises/collections/vec1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index ac3d9f1a..f6bc837c 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -20,6 +20,6 @@ mod tests { #[test] fn test_array_and_vec_similarity() { let (a, v) = array_and_vec(); - assert!(a.iter().zip(v.iter()).all(|(x, y)| x == y)); + assert_eq!(a, v[..]); } } From 04f1d079aa42a2f49af694bc92c67d731d31a53f Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Thu, 3 Dec 2020 17:48:30 +0100 Subject: [PATCH 002/476] feat(try_from_into): remove duplicate annotation --- exercises/conversions/try_from_into.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 897b364e..e405c3f4 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -102,7 +102,6 @@ mod tests { assert!(c.is_err()); } #[test] - #[test] fn test_array_correct() { let c: Result = [183, 65, 14].try_into(); assert_eq!( From 033bf1198fc8bfce1b570e49da7cde010aa552e3 Mon Sep 17 00:00:00 2001 From: JuliaCao Date: Mon, 7 Dec 2020 06:37:19 -0800 Subject: [PATCH 003/476] feat: match exercise order to book chapters (#541) Added exercise to book chapter mapping table to exercise README --- exercises/README.md | 23 ++ info.toml | 634 ++++++++++++++++++++------------------------ 2 files changed, 304 insertions(+), 353 deletions(-) create mode 100644 exercises/README.md diff --git a/exercises/README.md b/exercises/README.md new file mode 100644 index 00000000..725edd7b --- /dev/null +++ b/exercises/README.md @@ -0,0 +1,23 @@ +# Exercise to Book Chapter mapping + +| Exercise | Book Chapter | +|------------------------|--------------| +| variables | §3.1 | +| functions | §3.3 | +| if | §3.5 | +| move_semantics | §4.1 | +| primitive_types | §4.3 | +| structs | §5.1 | +| enums | §6 | +| modules | §7.2 | +| strings | §8.2 | +| error_handling | §9 | +| generics | §10 | +| option | §10.1 | +| traits | §10.2 | +| tests | §11.1 | +| standard_library_types | §13.2 | +| threads | §16.1 | +| macros | §19.6 | +| clippy | n/a | +| conversions | n/a | diff --git a/info.toml b/info.toml index cc12c99d..1b2eec21 100644 --- a/info.toml +++ b/info.toml @@ -71,31 +71,6 @@ Read more about constants under 'Differences Between Variables and Constants' in https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants """ -# IF - -[[exercises]] -name = "if1" -path = "exercises/if/if1.rs" -mode = "test" -hint = """ -It's possible to do this in one line if you would like! -Some similar examples from other languages: -- In C(++) this would be: `a > b ? a : b` -- In Python this would be: `a if a > b else b` -Remember in Rust that: -- the `if` condition does not need to be surrounded by parentheses -- `if`/`else` conditionals are expressions -- Each condition is followed by a `{}` block.""" - -[[exercises]] -name = "if2" -path = "exercises/if/if2.rs" -mode = "test" -hint = """ -For that first compiler error, it's important in Rust that each conditional -block return the same type! To get the tests passing, you will need a couple -conditions checking different input values.""" - # FUNCTIONS [[exercises]] @@ -146,6 +121,31 @@ They are not the same. There are two solutions: 1. Add a `return` ahead of `num * num;` 2. remove `;`, make it to be `num * num`""" +# IF + +[[exercises]] +name = "if1" +path = "exercises/if/if1.rs" +mode = "test" +hint = """ +It's possible to do this in one line if you would like! +Some similar examples from other languages: +- In C(++) this would be: `a > b ? a : b` +- In Python this would be: `a if a > b else b` +Remember in Rust that: +- the `if` condition does not need to be surrounded by parentheses +- `if`/`else` conditionals are expressions +- Each condition is followed by a `{}` block.""" + +[[exercises]] +name = "if2" +path = "exercises/if/if2.rs" +mode = "test" +hint = """ +For that first compiler error, it's important in Rust that each conditional +block return the same type! To get the tests passing, you will need a couple +conditions checking different input values.""" + # TEST 1 [[exercises]] @@ -154,6 +154,62 @@ path = "exercises/quiz1.rs" mode = "test" hint = "No hints this time ;)" +# MOVE SEMANTICS + +[[exercises]] +name = "move_semantics1" +path = "exercises/move_semantics/move_semantics1.rs" +mode = "compile" +hint = """ +So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 13, +right? The fix for this is going to be adding one keyword, and the addition is NOT on line 13 +where the error is.""" + +[[exercises]] +name = "move_semantics2" +path = "exercises/move_semantics/move_semantics2.rs" +mode = "compile" +hint = """ +So `vec0` is being *moved* into the function `fill_vec` when we call it on +line 10, which means it gets dropped at the end of `fill_vec`, which means we +can't use `vec0` again on line 13 (or anywhere else in `main` after the +`fill_vec` call for that matter). We could fix this in a few ways, try them +all! +1. Make another, separate version of the data that's in `vec0` and pass that + to `fill_vec` instead. +2. Make `fill_vec` borrow its argument instead of taking ownership of it, + and then copy the data within the function in order to return an owned + `Vec` +3. Make `fill_vec` *mutably* borrow its argument (which will need to be + mutable), modify it directly, then not return anything. Then you can get rid + of `vec1` entirely -- note that this will change what gets printed by the + first `println!`""" + +[[exercises]] +name = "move_semantics3" +path = "exercises/move_semantics/move_semantics3.rs" +mode = "compile" +hint = """ +The difference between this one and the previous ones is that the first line +of `fn fill_vec` that had `let mut vec = vec;` is no longer there. You can, +instead of adding that line back, add `mut` in one place that will change +an existing binding to be a mutable binding instead of an immutable one :)""" + +[[exercises]] +name = "move_semantics4" +path = "exercises/move_semantics/move_semantics4.rs" +mode = "compile" +hint = """ +Stop reading whenever you feel like you have enough direction :) Or try +doing one step and then fixing the compiler errors that result! +So the end goal is to: + - get rid of the first line in main that creates the new vector + - so then `vec0` doesn't exist, so we can't pass it to `fill_vec` + - we don't want to pass anything to `fill_vec`, so its signature should + reflect that it does not take any arguments + - 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`""" + # PRIMITIVE TYPES [[exercises]] @@ -255,6 +311,51 @@ For calculate_transport_fees: Bigger is more expensive usually, we don't have si Have a look in The Book, to find out more about method implementations: https://doc.rust-lang.org/book/ch05-03-method-syntax.html""" +# ENUMS + +[[exercises]] +name = "enums1" +path = "exercises/enums/enums1.rs" +mode = "compile" +hint = """ +Hint: The declaration of the enumeration type has not been defined yet.""" + +[[exercises]] +name = "enums2" +path = "exercises/enums/enums2.rs" +mode = "compile" +hint = """ +Hint: you can create enumerations that have different variants with different types +such as no data, anonymous structs, a single string, tuples, ...etc""" + +[[exercises]] +name = "enums3" +path = "exercises/enums/enums3.rs" +mode = "test" +hint = "No hints this time ;)" + +# MODULES + +[[exercises]] +name = "modules1" +path = "exercises/modules/modules1.rs" +mode = "compile" +hint = """ +Everything is private in Rust by default-- but there's a keyword we can use +to make something public! The compiler error should point to the thing that +needs to be public.""" + +[[exercises]] +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.""" + # STRINGS [[exercises]] @@ -286,248 +387,6 @@ path = "exercises/quiz2.rs" mode = "compile" hint = "No hints this time ;)" -# ENUMS - -[[exercises]] -name = "enums1" -path = "exercises/enums/enums1.rs" -mode = "compile" -hint = """ -Hint: The declaration of the enumeration type has not been defined yet.""" - -[[exercises]] -name = "enums2" -path = "exercises/enums/enums2.rs" -mode = "compile" -hint = """ -Hint: you can create enumerations that have different variants with different types -such as no data, anonymous structs, a single string, tuples, ...etc""" - -[[exercises]] -name = "enums3" -path = "exercises/enums/enums3.rs" -mode = "test" -hint = "No hints this time ;)" - -# TESTS - -[[exercises]] -name = "tests1" -path = "exercises/tests/tests1.rs" -mode = "test" -hint = """ -You don't even need to write any code to test -- you can just test values and run that, even -though you wouldn't do that in real life :) `assert!` is a macro that needs an argument. -Depending on the value of the argument, `assert!` will do nothing (in which case the test will -pass) or `assert!` will panic (in which case the test will fail). So try giving different values -to `assert!` and see which ones compile, which ones pass, and which ones fail :)""" - -[[exercises]] -name = "tests2" -path = "exercises/tests/tests2.rs" -mode = "test" -hint = """ -Like the previous exercise, you don't need to write any code to get this test to compile and -run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two -values that are equal! Try giving it two arguments that are different! Try giving it two values -that are of different types! Try switching which argument comes first and which comes second!""" - -[[exercises]] -name = "tests3" -path = "exercises/tests/tests3.rs" -mode = "test" -hint = """ -You can call a function right where you're passing arguments to `assert!` -- so you could do -something like `assert!(having_fun())`. If you want to check that you indeed get false, you -can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" - -# TEST 3 - -[[exercises]] -name = "quiz3" -path = "exercises/quiz3.rs" -mode = "test" -hint = "No hints this time ;)" - -# MODULES - -[[exercises]] -name = "modules1" -path = "exercises/modules/modules1.rs" -mode = "compile" -hint = """ -Everything is private in Rust by default-- but there's a keyword we can use -to make something public! The compiler error should point to the thing that -needs to be public.""" - -[[exercises]] -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.""" - -# COLLECTIONS - -[[exercises]] -name = "collections1" -path = "exercises/collections/vec1.rs" -mode = "test" -hint = """ -In Rust, there are two ways to define a Vector. - -1. One way is to use the `Vec::new()` function to create a new vector - and fill it with the `push()` method. - -2. The second way, which is simpler is to use the `vec![]` macro and - define your elements inside the square brackets. - -Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html -of the Rust book to learn more. -""" - -[[exercises]] -name = "collections2" -path = "exercises/collections/vec2.rs" -mode = "test" -hint = """ -Hint 1: `i` is each element from the Vec as they are being iterated. - Can you try multiplying this? - -Hint 2: Check the suggestion from the compiler error ;) -""" - -[[exercises]] -name = "collections3" -path = "exercises/collections/hashmap1.rs" -mode = "test" -hint = """ -Hint 1: Take a look at the return type of the function to figure out - the type for the `basket`. - -Hint 2: Number of fruits should be at least 5. And you have to put - at least three different types of fruits. -""" - -[[exercises]] -name = "collections4" -path = "exercises/collections/hashmap2.rs" -mode = "test" -hint = """ -Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this. - -Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value -""" - -# MACROS - -[[exercises]] -name = "macros1" -path = "exercises/macros/macros1.rs" -mode = "compile" -hint = """ -When you call a macro, you need to add something special compared to a -regular function call. If you're stuck, take a look at what's inside -`my_macro`.""" - -[[exercises]] -name = "macros2" -path = "exercises/macros/macros2.rs" -mode = "compile" -hint = """ -Macros don't quite play by the same rules as the rest of Rust, in terms of -what's available where. - -Unlike other things in Rust, the order of "where you define a macro" versus -"where you use it" actually matters.""" - -[[exercises]] -name = "macros3" -path = "exercises/macros/macros3.rs" -mode = "compile" -hint = """ -In order to use a macro outside of its module, you need to do something -special to the module to lift the macro out into its parent. - -The same trick also works on "extern crate" statements for crates that have -exported macros, if you've seen any of those around.""" - -[[exercises]] -name = "macros4" -path = "exercises/macros/macros4.rs" -mode = "compile" -hint = """ -You only need to add a single character to make this compile. -The way macros are written, it wants to see something between each -"macro arm", so it can separate them.""" -# TEST 4 - -[[exercises]] -name = "quiz4" -path = "exercises/quiz4.rs" -mode = "test" -hint = "No hints this time ;)" - -# MOVE SEMANTICS - -[[exercises]] -name = "move_semantics1" -path = "exercises/move_semantics/move_semantics1.rs" -mode = "compile" -hint = """ -So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 13, -right? The fix for this is going to be adding one keyword, and the addition is NOT on line 13 -where the error is.""" - -[[exercises]] -name = "move_semantics2" -path = "exercises/move_semantics/move_semantics2.rs" -mode = "compile" -hint = """ -So `vec0` is being *moved* into the function `fill_vec` when we call it on -line 10, which means it gets dropped at the end of `fill_vec`, which means we -can't use `vec0` again on line 13 (or anywhere else in `main` after the -`fill_vec` call for that matter). We could fix this in a few ways, try them -all! -1. Make another, separate version of the data that's in `vec0` and pass that - to `fill_vec` instead. -2. Make `fill_vec` borrow its argument instead of taking ownership of it, - and then copy the data within the function in order to return an owned - `Vec` -3. Make `fill_vec` *mutably* borrow its argument (which will need to be - mutable), modify it directly, then not return anything. Then you can get rid - of `vec1` entirely -- note that this will change what gets printed by the - first `println!`""" - -[[exercises]] -name = "move_semantics3" -path = "exercises/move_semantics/move_semantics3.rs" -mode = "compile" -hint = """ -The difference between this one and the previous ones is that the first line -of `fn fill_vec` that had `let mut vec = vec;` is no longer there. You can, -instead of adding that line back, add `mut` in one place that will change -an existing binding to be a mutable binding instead of an immutable one :)""" - -[[exercises]] -name = "move_semantics4" -path = "exercises/move_semantics/move_semantics4.rs" -mode = "compile" -hint = """ -Stop reading whenever you feel like you have enough direction :) Or try -doing one step and then fixing the compiler errors that result! -So the end goal is to: - - get rid of the first line in main that creates the new vector - - so then `vec0` doesn't exist, so we can't pass it to `fill_vec` - - we don't want to pass anything to `fill_vec`, so its signature should - reflect that it does not take any arguments - - 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`""" - # ERROR HANDLING [[exercises]] @@ -607,6 +466,40 @@ 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""" +# Generics + +[[exercises]] +name = "generics1" +path = "exercises/generics/generics1.rs" +mode = "compile" +hint = """ +Vectors in rust make use of generics to create dynamically sized arrays of any type. +You need to tell the compiler what type we are pushing onto this vector.""" + +[[exercises]] +name = "generics2" +path = "exercises/generics/generics2.rs" +mode = "test" +hint = """ +Currently we are wrapping only values of type 'u32'. +Maybe we could update the explicit references to this data type somehow? + +If you are still stuck https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions +""" + +[[exercises]] +name = "generics3" +path = "exercises/generics/generics3.rs" +mode = "test" +hint = """ +To find the best solution to this challenge you're going to need to think back to your +knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;" + +This is definitely harder than the last two exercises! You need to think about not only making the +ReportCard struct generic, but also the correct property - you will need to change the implementation +of the struct slightly too...you can do it! +""" + # OPTIONS / RESULTS [[exercises]] @@ -649,21 +542,67 @@ hint = """ 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 :)""" -# CLIPPY +# TRAITS [[exercises]] -name = "clippy1" -path = "exercises/clippy/clippy1.rs" -mode = "clippy" +name = "traits1" +path = "exercises/traits/traits1.rs" +mode = "test" hint = """ -Floating point calculations are usually imprecise, so asking if two values are exactly equal is asking for trouble""" +A discussion about Traits in Rust can be found at: +https://doc.rust-lang.org/book/ch10-02-traits.html +""" [[exercises]] -name = "clippy2" -path = "exercises/clippy/clippy2.rs" -mode = "clippy" +name = "traits2" +path = "exercises/traits/traits2.rs" +mode = "test" hint = """ -`for` loops over Option values are more clearly expressed as an `if let`""" +Notice how the trait takes ownership of 'self',and returns `Self'. +Try mutating the incoming string vector. + +Vectors provide suitable methods for adding an element at the end. See +the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html""" + +# TESTS + +[[exercises]] +name = "tests1" +path = "exercises/tests/tests1.rs" +mode = "test" +hint = """ +You don't even need to write any code to test -- you can just test values and run that, even +though you wouldn't do that in real life :) `assert!` is a macro that needs an argument. +Depending on the value of the argument, `assert!` will do nothing (in which case the test will +pass) or `assert!` will panic (in which case the test will fail). So try giving different values +to `assert!` and see which ones compile, which ones pass, and which ones fail :)""" + +[[exercises]] +name = "tests2" +path = "exercises/tests/tests2.rs" +mode = "test" +hint = """ +Like the previous exercise, you don't need to write any code to get this test to compile and +run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two +values that are equal! Try giving it two arguments that are different! Try giving it two values +that are of different types! Try switching which argument comes first and which comes second!""" + +[[exercises]] +name = "tests3" +path = "exercises/tests/tests3.rs" +mode = "test" +hint = """ +You can call a function right where you're passing arguments to `assert!` -- so you could do +something like `assert!(having_fun())`. If you want to check that you indeed get false, you +can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" + +# TEST 3 + +[[exercises]] +name = "quiz3" +path = "exercises/quiz3.rs" +mode = "test" +hint = "No hints this time ;)" # STANDARD LIBRARY TYPES @@ -697,27 +636,6 @@ inside the loop but still in the main thread. `child_numbers` should be a clone of the Arc of the numbers instead of a thread-local copy of the numbers.""" -[[exercises]] -name = "iterators1" -path = "exercises/standard_library_types/iterators1.rs" -mode = "compile" -hint = """ -Step 1: -We need to apply something to the collection `my_fav_fruits` before we start to go through -it. What could that be? Take a look at the struct definition for a vector for inspiration: -https://doc.rust-lang.org/std/vec/struct.Vec.html. - - -Step 2 & step 2.1: -Very similar to the lines above and below. You've got this! - - -Step 3: -An iterator goes through all elements in a collection, but what if we've run out of -elements? What should we expect here? If you're stuck, take a look at -https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. -""" - [[exercises]] name = "iterators2" path = "exercises/standard_library_types/iterators2.rs" @@ -761,62 +679,6 @@ a mutable variable. Or, you might write code utilizing recursion and a match clause. In Rust you can take another functional approach, computing the factorial elegantly with ranges and iterators.""" -# TRAITS - -[[exercises]] -name = "traits1" -path = "exercises/traits/traits1.rs" -mode = "test" -hint = """ -A discussion about Traits in Rust can be found at: -https://doc.rust-lang.org/book/ch10-02-traits.html -""" - -[[exercises]] -name = "traits2" -path = "exercises/traits/traits2.rs" -mode = "test" -hint = """ -Notice how the trait takes ownership of 'self',and returns `Self'. -Try mutating the incoming string vector. - -Vectors provide suitable methods for adding an element at the end. See -the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html""" - -# Generics - -[[exercises]] -name = "generics1" -path = "exercises/generics/generics1.rs" -mode = "compile" -hint = """ -Vectors in rust make use of generics to create dynamically sized arrays of any type. -You need to tell the compiler what type we are pushing onto this vector.""" - -[[exercises]] -name = "generics2" -path = "exercises/generics/generics2.rs" -mode = "test" -hint = """ -Currently we are wrapping only values of type 'u32'. -Maybe we could update the explicit references to this data type somehow? - -If you are still stuck https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions -""" - -[[exercises]] -name = "generics3" -path = "exercises/generics/generics3.rs" -mode = "test" -hint = """ -To find the best solution to this challenge you're going to need to think back to your -knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;" - -This is definitely harder than the last two exercises! You need to think about not only making the -ReportCard struct generic, but also the correct property - you will need to change the implementation -of the struct slightly too...you can do it! -""" - # THREADS [[exercises]] @@ -856,6 +718,72 @@ If you've learned from the sample solutions, I encourage you to come back to this exercise and try it again in a few days to reinforce what you've learned :)""" +# MACROS + +[[exercises]] +name = "macros1" +path = "exercises/macros/macros1.rs" +mode = "compile" +hint = """ +When you call a macro, you need to add something special compared to a +regular function call. If you're stuck, take a look at what's inside +`my_macro`.""" + +[[exercises]] +name = "macros2" +path = "exercises/macros/macros2.rs" +mode = "compile" +hint = """ +Macros don't quite play by the same rules as the rest of Rust, in terms of +what's available where. + +Unlike other things in Rust, the order of "where you define a macro" versus +"where you use it" actually matters.""" + +[[exercises]] +name = "macros3" +path = "exercises/macros/macros3.rs" +mode = "compile" +hint = """ +In order to use a macro outside of its module, you need to do something +special to the module to lift the macro out into its parent. + +The same trick also works on "extern crate" statements for crates that have +exported macros, if you've seen any of those around.""" + +[[exercises]] +name = "macros4" +path = "exercises/macros/macros4.rs" +mode = "compile" +hint = """ +You only need to add a single character to make this compile. +The way macros are written, it wants to see something between each +"macro arm", so it can separate them.""" + +# TEST 4 + +[[exercises]] +name = "quiz4" +path = "exercises/quiz4.rs" +mode = "test" +hint = "No hints this time ;)" + +# CLIPPY + +[[exercises]] +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""" + +[[exercises]] +name = "clippy2" +path = "exercises/clippy/clippy2.rs" +mode = "clippy" +hint = """ +`for` loops over Option values are more clearly expressed as an `if let`""" + # TYPE CONVERSIONS [[exercises]] From 30644c9a062b825c0ea89435dc59f0cad86b110e Mon Sep 17 00:00:00 2001 From: Peter N Date: Tue, 8 Dec 2020 06:08:25 -0300 Subject: [PATCH 004/476] fix: gives a bit more context to magic number --- exercises/threads/threads1.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index 1785e8ce..b475b4a1 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -1,7 +1,8 @@ // threads1.rs // Make this compile! Execute `rustlings hint threads1` for hints :) // The idea is the thread spawned on line 21 is completing jobs while the main thread is -// monitoring progress until 10 jobs are completed. If you see 6 lines +// monitoring progress until 10 jobs are completed. Because of the difference between the +// spawned threads' sleep time, and the waiting threads sleep time, when you see 6 lines // of "waiting..." and the program ends without timing out when running, // you've got it :) From 26110da7cadc4ab7614730c2d0b1e514a2763d3d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 8 Dec 2020 10:12:57 +0100 Subject: [PATCH 005/476] docs: add pcn as a contributor * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 84b2365e..388bf5ff 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -637,6 +637,15 @@ "contributions": [ "maintenance" ] + }, + { + "login": "pcn", + "name": "Peter N", + "avatar_url": "https://avatars2.githubusercontent.com/u/1056756?v=4", + "profile": "https://github.com/pcn", + "contributions": [ + "maintenance" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index fd45d945..49ceb2c9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![crab pet](https://i.imgur.com/LbZJgmm.gif) -[![All Contributors](https://img.shields.io/badge/all_contributors-68-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -233,6 +233,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Axel Viala

💻
Mohammed Sazid Al Rashid

🖋 💻
Caleb Webber

🚧 +
Peter N

🚧 From 90cfb6ff28377531bfc34acb70547bdb13374f6b Mon Sep 17 00:00:00 2001 From: JuliaCao Date: Sat, 12 Dec 2020 10:21:23 -0800 Subject: [PATCH 006/476] fix: added missing exercises to info.toml --- exercises/README.md | 1 + info.toml | 63 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/exercises/README.md b/exercises/README.md index 725edd7b..0c715247 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -10,6 +10,7 @@ | structs | §5.1 | | enums | §6 | | modules | §7.2 | +| collections | §8.1 | | strings | §8.2 | | error_handling | §9 | | generics | §10 | diff --git a/info.toml b/info.toml index 1b2eec21..f1fc3981 100644 --- a/info.toml +++ b/info.toml @@ -356,6 +356,52 @@ its internal structure (the `fruits` and `veggies` modules and associated constants). It's almost there except for one keyword missing for each constant.""" +# COLLECTIONS + +[[exercises]] +name = "collections1" +path = "exercises/collections/vec1.rs" +mode = "test" +hint = """ +In Rust, there are two ways to define a Vector. +1. One way is to use the `Vec::new()` function to create a new vector + and fill it with the `push()` method. +2. The second way, which is simpler is to use the `vec![]` macro and + define your elements inside the square brackets. +Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html +of the Rust book to learn more. +""" + +[[exercises]] +name = "collections2" +path = "exercises/collections/vec2.rs" +mode = "test" +hint = """ +Hint 1: `i` is each element from the Vec as they are being iterated. + Can you try multiplying this? +Hint 2: Check the suggestion from the compiler error ;) +""" + +[[exercises]] +name = "collections3" +path = "exercises/collections/hashmap1.rs" +mode = "test" +hint = """ +Hint 1: Take a look at the return type of the function to figure out + the type for the `basket`. +Hint 2: Number of fruits should be at least 5. And you have to put + at least three different types of fruits. +""" + +[[exercises]] +name = "collections4" +path = "exercises/collections/hashmap2.rs" +mode = "test" +hint = """ +Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this. +Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value +""" + # STRINGS [[exercises]] @@ -636,6 +682,23 @@ inside the loop but still in the main thread. `child_numbers` should be a clone of the Arc of the numbers instead of a thread-local copy of the numbers.""" +[[exercises]] +name = "iterators1" +path = "exercises/standard_library_types/iterators1.rs" +mode = "compile" +hint = """ +Step 1: +We need to apply something to the collection `my_fav_fruits` before we start to go through +it. What could that be? Take a look at the struct definition for a vector for inspiration: +https://doc.rust-lang.org/std/vec/struct.Vec.html. +Step 2 & step 2.1: +Very similar to the lines above and below. You've got this! +Step 3: +An iterator goes through all elements in a collection, but what if we've run out of +elements? What should we expect here? If you're stuck, take a look at +https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. +""" + [[exercises]] name = "iterators2" path = "exercises/standard_library_types/iterators2.rs" From bcf14cf677adb3a38a3ac3ca53f3c69f61153025 Mon Sep 17 00:00:00 2001 From: seancad <47405611+seancad@users.noreply.github.com> Date: Tue, 15 Dec 2020 00:32:46 -0700 Subject: [PATCH 007/476] fix: update structs README --- exercises/structs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/structs/README.md b/exercises/structs/README.md index afbc72c8..d2d7dc24 100644 --- a/exercises/structs/README.md +++ b/exercises/structs/README.md @@ -4,4 +4,4 @@ Rust has three struct types: a classic c struct, a tuple struct, and a unit stru #### Book Sections -- [Structures](https://doc.rust-lang.org/rust-by-example/custom_types/structs.html) +- [Structures](https://doc.rust-lang.org/book/ch05-01-defining-structs.html) From 4ac70a99aea688a629e5d7ef99bb8686fa7f6301 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 15 Dec 2020 08:33:47 +0100 Subject: [PATCH 008/476] docs: add seancad as a contributor * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 388bf5ff..1549aa45 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -646,6 +646,15 @@ "contributions": [ "maintenance" ] + }, + { + "login": "seancad", + "name": "seancad", + "avatar_url": "https://avatars1.githubusercontent.com/u/47405611?v=4", + "profile": "https://github.com/seancad", + "contributions": [ + "maintenance" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index 49ceb2c9..7a2c94c6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![crab pet](https://i.imgur.com/LbZJgmm.gif) -[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -234,6 +234,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Mohammed Sazid Al Rashid

🖋 💻
Caleb Webber

🚧
Peter N

🚧 +
seancad

🚧 From 0ef95947cc30482e63a7045be6cc2fb6f6dcb4cc Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Sun, 27 Dec 2020 12:36:38 +0100 Subject: [PATCH 009/476] fix(functions2): Change signature to trigger precise error message: (#605) Now trigger this error: ``` error: expected type, found `)` --> exercises/functions/functions2.rs:10:16 | 10 | fn call_me(num:) { | ^ expected type ``` --- exercises/functions/functions2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 108ba38b..5721a172 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -7,7 +7,7 @@ fn main() { call_me(3); } -fn call_me(num) { +fn call_me(num:) { for i in 0..num { println!("Ring! Call number {}", i + 1); } From 28020d0c54e795c465f59cb92954599de8834549 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Dec 2020 11:23:08 +0100 Subject: [PATCH 010/476] docs: Add note on uninstalling to README --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 7a2c94c6..9512ac5c 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,24 @@ cargo uninstall rustlings rm -r rustlings/ # or on Windows: rmdir /s rustlings ``` +## Uninstalling Rustlings + +If you want to remove Rustlings from your system, there's two steps. First, you'll need to remove the exercises folder that the install script created +for you: + +``` bash +rm -rf rustlings # or your custom folder name, if you chose and or renamed it +``` + +Second, since Rustlings got installed via `cargo install`, it's only reasonable to assume that you can also remove it using Cargo, and +exactly that is the case. Run `cargo uninstall` to remove the `rustlings` binary: + +``` bash +cargo uninstall rustlings +``` + +Now you should be done! + ## Completion Rustlings isn't done; there are a couple of sections that are very experimental and don't have proper documentation. These include: From 44d39112ff122b29c9793fe52e605df1612c6490 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Dec 2020 11:34:52 +0100 Subject: [PATCH 011/476] feat: Rewrite default out text This has been in place for a long time now, before we had an install script, so it ended up repeating a bunch of the same things that the install script does automatically. I rewrote it so that it gives more helpful information about how you're supposed to do Rustlings. Hopefully this will reduce the number of "I started Rustlings and it gave me an error" issues (no offense to anyone who opened one of those, it was pretty unclear that it _wasn't_ an error). --- default_out.txt | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/default_out.txt b/default_out.txt index 05267591..44b7734c 100644 --- a/default_out.txt +++ b/default_out.txt @@ -1,19 +1,25 @@ Thanks for installing Rustlings! -Is this your first time? +Is this your first time? Don't worry, Rustlings was made for beginners! We are +going to teach you a lot of things about Rust, but before we can get +started, here's a couple of notes about how Rustlings operates: -Let's make sure you're up to speed: -- You have Rust installed, preferably via `rustup` -- You have `~/.cargo/bin` added to your PATH variable -- You have cloned this repository (https://github.com/rust-lang/rustlings) -- You have installed Rust language support for your editor -- You have locally installed the `rustlings` command by running an - installation script or manually executing: +1. The central concept behind Rustlings is that you solve exercises. These + exercises usually have some sort of syntax error in them, which will cause + them to fail compliation or testing. Sometimes there's a logic error instead + of a syntax error. No matter what error, it's your job to find it and fix it! + You'll know when you fixed it because then, the exercise will compile and + Rustlings will be able to move on to the next exercise. +2. If you run Rustlings in watch mode (which we recommend), it'll automatically + start with the first exercise. Don't get confused by an error message popping + up as soon as you run Rustlings! This is part of the exercise that you're + supposed to solve, so open the exercise file in an editor and start your + detective work! +3. If you're stuck on an exercise, there is a helpful hint you can view by typing + 'hint' (in watch mode), or running `rustlings hint myexercise`. +4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub! + (https://github.com/rust-lang/rustlings/issues/new). We look at every issue, + and sometimes, other learners do too so you can help each other out! -cargo install --force --path . - -If you've done all of this (or even most of it), congrats! You're ready -to start working with Rust. - -To get started, run `rustlings watch` in order to get the first exercise. -Make sure to have your editor open! +Got all that? Great! To get started, run `rustlings watch` in order to get the first +exercise. Make sure to have your editor open! From a303d508cf0c5bc20bb50bd388b2545bf80672ac Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Dec 2020 11:39:26 +0100 Subject: [PATCH 012/476] release: 4.3.0 --- CHANGELOG.md | 23 ++ Cargo.lock | 590 +++++++++++++++++++++++++-------------------------- Cargo.toml | 2 +- README.md | 2 +- src/main.rs | 2 +- 5 files changed, 320 insertions(+), 299 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d58d4e6b..3988826e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ + +## 4.3.0 (2020-12-29) + +#### Features + +* Rewrite default out text ([44d39112](https://github.com/rust-lang/rustlings/commit/44d39112ff122b29c9793fe52e605df1612c6490)) +* match exercise order to book chapters (#541) ([033bf119](https://github.com/rust-lang/rustlings/commit/033bf1198fc8bfce1b570e49da7cde010aa552e3)) +* Crab? (#586) ([fa9f522b](https://github.com/rust-lang/rustlings/commit/fa9f522b7f043d7ef73a39f003a9272dfe72c4f4)) +* add "rustlings list" command ([838f9f30](https://github.com/rust-lang/rustlings/commit/838f9f30083d0b23fd67503dcf0fbeca498e6647)) +* **try_from_into:** remove duplicate annotation ([04f1d079](https://github.com/rust-lang/rustlings/commit/04f1d079aa42a2f49af694bc92c67d731d31a53f)) + +#### Bug Fixes + +* update structs README ([bcf14cf6](https://github.com/rust-lang/rustlings/commit/bcf14cf677adb3a38a3ac3ca53f3c69f61153025)) +* added missing exercises to info.toml ([90cfb6ff](https://github.com/rust-lang/rustlings/commit/90cfb6ff28377531bfc34acb70547bdb13374f6b)) +* gives a bit more context to magic number ([30644c9a](https://github.com/rust-lang/rustlings/commit/30644c9a062b825c0ea89435dc59f0cad86b110e)) +* **functions2:** Change signature to trigger precise error message: (#605) ([0ef95947](https://github.com/rust-lang/rustlings/commit/0ef95947cc30482e63a7045be6cc2fb6f6dcb4cc)) +* **structs1:** Adjust wording (#573) ([9334783d](https://github.com/rust-lang/rustlings/commit/9334783da31d821cc59174fbe8320df95828926c)) +* **try_from_into:** + * type error ([4f4cfcf3](https://github.com/rust-lang/rustlings/commit/4f4cfcf3c36c8718c7c170c9c3a6935e6ef0618c)) + * Update description (#584) ([96347df9](https://github.com/rust-lang/rustlings/commit/96347df9df294f01153b29d9ad4ba361f665c755)) +* **vec1:** Have test compare every element in a and v ([9b6c6293](https://github.com/rust-lang/rustlings/commit/9b6c629397b24b944f484f5b2bbd8144266b5695)) + ## 4.2.0 (2020-11-07) diff --git a/Cargo.lock b/Cargo.lock index 9f90e0a1..4a4313e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,917 +4,915 @@ name = "aho-corasick" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" dependencies = [ - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8", ] [[package]] name = "assert_cmd" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc477793bd82ec39799b6f6b3df64938532fdf2ab0d49ef817eac65856a5a1e" dependencies = [ - "escargot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "escargot", + "predicates", + "predicates-core", + "predicates-tree", ] [[package]] name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "termion", + "winapi 0.3.8", ] [[package]] name = "autocfg" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" [[package]] name = "bitflags" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" [[package]] name = "cfg-if" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" [[package]] name = "clap" version = "2.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] name = "clicolors-control" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "lazy_static", + "libc", + "winapi 0.3.8", ] [[package]] name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", ] [[package]] name = "console" version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" dependencies = [ - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "clicolors-control", + "encode_unicode", + "lazy_static", + "libc", + "parking_lot", + "regex", + "termios", + "unicode-width", + "winapi 0.3.8", ] [[package]] name = "console" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b147390a412132d75d10dd3b7b175a69cf5fd95032f7503c7091b8831ba10242" dependencies = [ - "clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "clicolors-control", + "encode_unicode", + "lazy_static", + "libc", + "regex", + "termios", + "unicode-width", + "winapi 0.3.8", ] [[package]] name = "difference" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "encode_unicode" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" [[package]] name = "escargot" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceb9adbf9874d5d028b5e4c5739d22b71988252b25c9c98fe7cf9738bee84597" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", + "log", + "serde", + "serde_json", ] [[package]] name = "filetime" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "redox_syscall", ] [[package]] name = "float-cmp" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" dependencies = [ - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits", ] [[package]] name = "fsevent" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "fsevent-sys", ] [[package]] name = "fsevent-sys" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "fuchsia-zircon-sys", ] [[package]] name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "indicatif" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" dependencies = [ - "console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "console 0.8.0", + "lazy_static", + "number_prefix", + "parking_lot", + "regex", ] [[package]] name = "inotify" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "inotify-sys", + "libc", ] [[package]] name = "inotify-sys" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "winapi 0.2.8", ] [[package]] name = "itoa" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" [[package]] name = "kernel32-sys" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] [[package]] name = "lazy_static" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" [[package]] name = "lazycell" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "libc" version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" [[package]] name = "lock_api" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" dependencies = [ - "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard", ] [[package]] name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", ] [[package]] name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" [[package]] name = "mio" version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" dependencies = [ - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", ] [[package]] name = "mio-extras" version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazycell", + "log", + "mio", + "slab", ] [[package]] name = "miow" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", ] [[package]] name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "libc", + "winapi 0.3.8", ] [[package]] name = "normalize-line-endings" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" [[package]] name = "notify" version = "4.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "filetime", + "fsevent", + "fsevent-sys", + "inotify", + "libc", + "mio", + "mio-extras", + "walkdir", + "winapi 0.3.8", ] [[package]] name = "num-traits" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" dependencies = [ - "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", ] [[package]] name = "number_prefix" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" dependencies = [ - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits", ] [[package]] name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] name = "parking_lot" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" dependencies = [ - "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "lock_api", + "parking_lot_core", + "rustc_version", ] [[package]] name = "parking_lot_core" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" dependencies = [ - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if", + "cloudabi", + "libc", + "rand", + "redox_syscall", + "rustc_version", + "smallvec", + "winapi 0.3.8", ] [[package]] name = "predicates" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53e09015b0d3f5a0ec2d4428f7559bb7b3fff341b4e159fedd1d57fac8b939ff" dependencies = [ - "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "difference", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", ] [[package]] name = "predicates-core" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" [[package]] name = "predicates-tree" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" dependencies = [ - "predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "predicates-core", + "treeline", ] [[package]] name = "proc-macro2" version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" dependencies = [ - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid", ] [[package]] name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" dependencies = [ - "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "libc", + "rand_chacha", + "rand_core 0.4.0", + "rand_hc", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi 0.3.8", ] [[package]] name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" dependencies = [ - "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "rand_core 0.3.1", ] [[package]] name = "rand_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" dependencies = [ - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0", ] [[package]] name = "rand_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" [[package]] name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "rand_isaac" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "rand_jitter" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "rand_core 0.4.0", + "winapi 0.3.8", ] [[package]] name = "rand_os" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.0", + "rdrand", + "winapi 0.3.8", ] [[package]] name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" dependencies = [ - "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg", + "rand_core 0.4.0", ] [[package]] name = "rand_xorshift" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "rdrand" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" dependencies = [ - "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1", ] [[package]] name = "redox_syscall" version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" [[package]] name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" dependencies = [ - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall", ] [[package]] name = "regex" version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" dependencies = [ - "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", + "utf8-ranges", ] [[package]] name = "regex-syntax" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ucd-util", ] [[package]] name = "rustc_version" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver", ] [[package]] name = "rustlings" -version = "4.2.0" +version = "4.3.0" dependencies = [ - "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", - "notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "assert_cmd", + "clap", + "console 0.7.7", + "glob", + "indicatif", + "notify", + "predicates", + "regex", + "serde", + "toml", ] [[package]] name = "ryu" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" [[package]] name = "same-file" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" dependencies = [ - "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util", ] [[package]] name = "scopeguard" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" [[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "semver-parser", ] [[package]] name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" dependencies = [ - "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" dependencies = [ - "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa", + "ryu", + "serde", ] [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" dependencies = [ - "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "numtoa", + "redox_syscall", + "redox_termios", ] [[package]] name = "termios" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" dependencies = [ - "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static", ] [[package]] name = "toml" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" dependencies = [ - "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde", ] [[package]] name = "treeline" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "ucd-util" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" [[package]] name = "unicode-width" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" [[package]] name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" [[package]] name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" [[package]] name = "walkdir" version = "2.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" dependencies = [ - "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "same-file", + "winapi 0.3.8", + "winapi-util", ] [[package]] name = "winapi" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8", ] [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "ws2_32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8", + "winapi-build", ] - -[metadata] -"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc477793bd82ec39799b6f6b3df64938532fdf2ab0d49ef817eac65856a5a1e" -"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" -"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" -"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" -"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" -"checksum console 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b147390a412132d75d10dd3b7b175a69cf5fd95032f7503c7091b8831ba10242" -"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" -"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" -"checksum escargot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ceb9adbf9874d5d028b5e4c5739d22b71988252b25c9c98fe7cf9738bee84597" -"checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" -"checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" -"checksum fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" -"checksum fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" -"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -"checksum indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" -"checksum inotify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8" -"checksum inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" -"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" -"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" -"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" -"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" -"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" -"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" -"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" -"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -"checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" -"checksum notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd" -"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" -"checksum number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" -"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" -"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" -"checksum predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "53e09015b0d3f5a0ec2d4428f7559bb7b3fff341b4e159fedd1d57fac8b939ff" -"checksum predicates-core 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" -"checksum predicates-tree 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" -"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" -"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" -"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" -"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" -"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" -"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" -"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" -"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" -"checksum serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e" -"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" -"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" -"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" -"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum treeline 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" -"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index ebce25eb..a0564c37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.2.0" +version = "4.3.0" authors = ["Marisa ", "Carol (Nichols || Goulding) "] edition = "2018" diff --git a/README.md b/README.md index 9512ac5c..a5371043 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Basically: Clone the repository, checkout to the latest tag, run `cargo install` ```bash git clone https://github.com/rust-lang/rustlings cd rustlings -git checkout tags/4.2.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) +git checkout tags/4.3.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) cargo install --force --path . ``` diff --git a/src/main.rs b/src/main.rs index 35f8df4d..bf35e4fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ mod verify; fn main() { let matches = App::new("rustlings") .version(crate_version!()) - .author("Olivia Hugger, Carol Nichols") + .author("Marisa, Carol Nichols") .about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code") .arg( Arg::with_name("nocapture") From 644c49f1e04cbb24e95872b3a52b07d692ae3bc8 Mon Sep 17 00:00:00 2001 From: xehpuk Date: Wed, 30 Dec 2020 22:56:04 +0100 Subject: [PATCH 013/476] fix: typo in default out text --- default_out.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default_out.txt b/default_out.txt index 44b7734c..b90d1e3a 100644 --- a/default_out.txt +++ b/default_out.txt @@ -6,7 +6,7 @@ started, here's a couple of notes about how Rustlings operates: 1. The central concept behind Rustlings is that you solve exercises. These exercises usually have some sort of syntax error in them, which will cause - them to fail compliation or testing. Sometimes there's a logic error instead + them to fail compilation or testing. Sometimes there's a logic error instead of a syntax error. No matter what error, it's your job to find it and fix it! You'll know when you fixed it because then, the exercise will compile and Rustlings will be able to move on to the next exercise. From ff6cba7205fc9b1a5cbb10dcf4f7887b153a4930 Mon Sep 17 00:00:00 2001 From: RoelofWobben <75732370+RoelofWobben@users.noreply.github.com> Date: Sun, 27 Dec 2020 10:49:55 +0100 Subject: [PATCH 014/476] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a5371043..16f8c3d8 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ Start-BitsTransfer -Source https://git.io/rustlings-win -Destination $env:TMP/in To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. +When you get a permission denied message then you have to exclude the directory where you placed the rustlings in your virus-scanner + ## Browser: [Run on Repl.it](https://repl.it/github/rust-lang/rustlings) From e9b42bbc2a20df848950375a5baafc0620017a9c Mon Sep 17 00:00:00 2001 From: Will Hayworth Date: Sun, 3 Jan 2021 03:42:39 -0800 Subject: [PATCH 015/476] docs: mention flatten in the options2 hint --- info.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/info.toml b/info.toml index ee4ab2f6..15cd3f3f 100644 --- a/info.toml +++ b/info.toml @@ -583,8 +583,7 @@ https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html Remember that Options can be stacked in if let and while let. For example: Some(Some(variable)) = variable2 - - +Also see Option::flatten """ [[exercises]] From c355ac6593e94e09459dea93a11371f132913123 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 4 Jan 2021 13:12:10 +0000 Subject: [PATCH 016/476] docs: update README.md [skip ci] --- README.md | 146 +++++++++++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 16f8c3d8..b67793d4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![crab pet](https://i.imgur.com/LbZJgmm.gif) -[![All Contributors](https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-71-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -169,97 +169,99 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + + +

Carol (Nichols || Goulding)

💻 🖋

QuietMisdreavus

💻 🖋

Robert M Lugg

🖋

Hynek Schlawack

💻

Katharina Fey

💻

lukabavdaz

💻 🖋

Erik Vesteraas

💻

delet0r

💻

Carol (Nichols || Goulding)

💻 🖋

QuietMisdreavus

💻 🖋

Robert M Lugg

🖋

Hynek Schlawack

💻

Katharina Fey

💻

lukabavdaz

💻 🖋

Erik Vesteraas

💻

delet0r

💻

Shaun Bennett

💻

Andrew Bagshaw

💻

Kyle Isom

💻

Colin Pitrat

💻

Zac Anger

💻

Matthias Geier

💻

Chris Pearce

💻

Yvan Sraka

💻

Shaun Bennett

💻

Andrew Bagshaw

💻

Kyle Isom

💻

Colin Pitrat

💻

Zac Anger

💻

Matthias Geier

💻

Chris Pearce

💻

Yvan Sraka

💻

Denys Smirnov

💻

eddyp

💻

Brian Kung

💻 🖋

Russell

💻

Dan Wilhelm

📖

Jesse

💻 🖋

Fredrik Jambrén

💻

Pete McFarlane

🖋

Denys Smirnov

💻

eddyp

💻

Brian Kung

💻 🖋

Russell

💻

Dan Wilhelm

📖

Jesse

💻 🖋

Fredrik Jambrén

💻

Pete McFarlane

🖋

nkanderson

💻 🖋

Ajax M

📖

Dylan Nugent

🖋

vyaslav

💻 🖋

George

💻

Thomas Holloway

💻 🖋

Jubilee

💻

WofWca

💻

nkanderson

💻 🖋

Ajax M

📖

Dylan Nugent

🖋

vyaslav

💻 🖋

George

💻

Thomas Holloway

💻 🖋

Jubilee

💻

WofWca

💻

Roberto Vidal

💻 📖 🤔 🚧

Jens

📖

Rahat Ahmed

📖

Abdou Seck

💻 🖋 👀

Katie

💻

Socrates

📖

gnodarse

🖋

Harrison Metzger

💻

Roberto Vidal

💻 📖 🤔 🚧

Jens

📖

Rahat Ahmed

📖

Abdou Seck

💻 🖋 👀

Katie

💻

Socrates

📖

gnodarse

🖋

Harrison Metzger

💻

Torben Jonas

💻 🖋

Paul Bissex

📖

Steven Mann

💻 🖋

Mario Reder

💻 🖋

skim

💻

Sanjay K

💻 🖋

Rohan Jain

💻

Said Aspen

💻 🖋

Torben Jonas

💻 🖋

Paul Bissex

📖

Steven Mann

💻 🖋

Mario Reder

💻 🖋

skim

💻

Sanjay K

💻 🖋

Rohan Jain

💻

Said Aspen

💻 🖋

Ufuk Celebi

💻

lebedevsergey

📖

Aleksei Trifonov

🖋

Darren Meehan

🖋

Jihchi Lee

🖋

Christofer Bertonha

🖋

Vivek Bharath Akupatni

💻 ⚠️

Dídac Sementé Fernández

💻 🖋

Ufuk Celebi

💻

lebedevsergey

📖

Aleksei Trifonov

🖋

Darren Meehan

🖋

Jihchi Lee

🖋

Christofer Bertonha

🖋

Vivek Bharath Akupatni

💻 ⚠️

Dídac Sementé Fernández

💻 🖋

Rob Story

💻

Siobhan Jacobson

💻

Evan Carroll

🖋

Jawaad Mahmood

🖋

Gaurang Tandon

🖋

Stefan Kupresak

🖋

Greg Leonard

🖋

Ryan McQuen

💻

Rob Story

💻

Siobhan Jacobson

💻

Evan Carroll

🖋

Jawaad Mahmood

🖋

Gaurang Tandon

🖋

Stefan Kupresak

🖋

Greg Leonard

🖋

Ryan McQuen

💻

Annika

👀

Axel Viala

💻

Mohammed Sazid Al Rashid

🖋 💻

Caleb Webber

🚧

Peter N

🚧

seancad

🚧

Annika

👀

Axel Viala

💻

Mohammed Sazid Al Rashid

🖋 💻

Caleb Webber

🚧

Peter N

🚧

seancad

🚧

Will Hayworth

🖋
- + + This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! From 6df08b411bc09fd10d510be74c80e9cc6164e145 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 4 Jan 2021 13:12:11 +0000 Subject: [PATCH 017/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 1549aa45..d2b0fae1 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -655,6 +655,15 @@ "contributions": [ "maintenance" ] + }, + { + "login": "wsh", + "name": "Will Hayworth", + "avatar_url": "https://avatars3.githubusercontent.com/u/181174?v=4", + "profile": "http://willhayworth.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 10965920fbdf8a1efc85bed869e55a1787006404 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Wed, 6 Jan 2021 11:12:33 +0200 Subject: [PATCH 018/476] fix(move_semantics4): Small readbility improvement (#617) * Small readbility improvement move_semantics4 doc * Remove `an` as it refers to the argument --- exercises/move_semantics/move_semantics4.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index a1c4a413..6308c296 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -18,7 +18,7 @@ fn main() { println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); } -// `fill_vec()` no longer take `vec: Vec` as argument +// `fill_vec()` no longer takes `vec: Vec` as argument fn fill_vec() -> Vec { let mut vec = vec; From 7857b0a689b0847f48d8c14cbd1865e3b812d5ca Mon Sep 17 00:00:00 2001 From: Christian Zeller Date: Wed, 6 Jan 2021 13:47:20 +0100 Subject: [PATCH 019/476] fix(threads1): line number correction --- exercises/threads/threads1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index b475b4a1..f31b317e 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -1,6 +1,6 @@ // threads1.rs // Make this compile! Execute `rustlings hint threads1` for hints :) -// The idea is the thread spawned on line 21 is completing jobs while the main thread is +// The idea is the thread spawned on line 22 is completing jobs while the main thread is // monitoring progress until 10 jobs are completed. Because of the difference between the // spawned threads' sleep time, and the waiting threads sleep time, when you see 6 lines // of "waiting..." and the program ends without timing out when running, From 621816fb561a9501aa15e8c3674ccdff3b2b24fe Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:54:33 +0000 Subject: [PATCH 020/476] 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 b67793d4..f489f93d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![crab pet](https://i.imgur.com/LbZJgmm.gif) -[![All Contributors](https://img.shields.io/badge/all_contributors-71-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-72-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -256,6 +256,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Peter N

🚧
seancad

🚧
Will Hayworth

🖋 +
Christian Zeller

🖋 From c24a78ae94b0e8527ee75908edeea136a7a3dbeb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Jan 2021 15:54:34 +0000 Subject: [PATCH 021/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d2b0fae1..46e68ae5 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -664,6 +664,15 @@ "contributions": [ "content" ] + }, + { + "login": "chrizel", + "name": "Christian Zeller", + "avatar_url": "https://avatars3.githubusercontent.com/u/20802?v=4", + "profile": "https://github.com/chrizel", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From fea86c29d6b0b29513e1cfb56b9eab5d4dcd121e Mon Sep 17 00:00:00 2001 From: fmoko Date: Fri, 8 Jan 2021 14:01:04 +0100 Subject: [PATCH 022/476] chore: Remove Readme GIF --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index f489f93d..987bb839 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -![crab pet](https://i.imgur.com/LbZJgmm.gif) [![All Contributors](https://img.shields.io/badge/all_contributors-72-orange.svg?style=flat-square)](#contributors-) From 5a0521e92c80c43d6451fcc520fd68e7f56106f8 Mon Sep 17 00:00:00 2001 From: Sang-Heon Jeon Date: Sat, 9 Jan 2021 00:07:13 +0900 Subject: [PATCH 023/476] feat(from_str) : add test for checking unnecessary trailing value --- exercises/conversions/from_str.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index af9eee6d..70ed1796 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -82,4 +82,16 @@ mod tests { fn missing_name_and_invalid_age() { ",one".parse::().unwrap(); } + + #[test] + #[should_panic] + fn trailing_comma() { + "John,32,".parse::().unwrap(); + } + + #[test] + #[should_panic] + fn trailing_comma_and_some_string() { + "John,32,man".parse::().unwrap(); + } } From 4f1374a6e7dd76d0f8769adf51495d5d0f9ea8a1 Mon Sep 17 00:00:00 2001 From: Sang-Heon Jeon Date: Sat, 9 Jan 2021 00:08:38 +0900 Subject: [PATCH 024/476] feat(from_into) : add test for checking unnecessary trailing value --- exercises/conversions/from_into.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index f24cf61b..9d84174d 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -115,4 +115,18 @@ mod tests { assert_eq!(p.name, "John"); assert_eq!(p.age, 30); } + + #[test] + fn test_trailing_comma() { + let p: Person = Person::from("Mike,32,"); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); + } + + #[test] + fn test_trailing_comma_and_some_string() { + let p: Person = Person::from("Mike,32,man"); + assert_eq!(p.name, "John"); + assert_eq!(p.age, 30); + } } From 0b9220c1fc5ae32438f64bf2f5bf5f47d33e3f3f Mon Sep 17 00:00:00 2001 From: Abdou Seck Date: Sat, 12 Dec 2020 13:45:37 -0500 Subject: [PATCH 025/476] Add looks_done method to Exercise to expose a resolution state --- src/exercise.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/exercise.rs b/src/exercise.rs index 283b2b90..7afa230a 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -232,6 +232,16 @@ path = "{}.rs""#, State::Pending(context) } + + // Check that the exercise looks to be solved using self.state() + // This is not the best way to check since + // the user can just remove the "I AM NOT DONE" string fromm the file + // without actually having solved anything. + // The only other way to truly check this would to compile and run + // the exercise; which would be both costly and counterintuitive + pub fn looks_done(&self) -> bool { + self.state() == State::Done + } } impl Display for Exercise { From 8bbe4ff1385c5c169c90cd3ff9253f9a91daaf8e Mon Sep 17 00:00:00 2001 From: Abdou Seck Date: Sat, 12 Dec 2020 13:48:25 -0500 Subject: [PATCH 026/476] feat(cli): Improve the list command with options, and then some 1. `rustlings list` should now display more than just the exercise names. Information such as file paths and exercises statuses should be displayed. The `--paths` option limits the displayed fields to only the path names; while the `--names` option limits the displayed fields to only exercise names. You can also control which exercises are displayed, by using the `--filter` option, or the `--solved` or `--unsolved` flags. Some use cases: - Fetching pending exercise files with the keyword "conversion" to pass to my editor: ```sh vim $(rustlings list --filter "conversion" --paths --unsolved) ``` - Fetching exercise names with keyword "conversion" to pass to `rustlings run`: ```sh for exercise in $(rustlings list --filter "conversion" --names) do rustlings run ${exercise} done ``` 2. This should also fix #465, and will likely fix #585, as well. That bug mentioned in those issues has to do with the way the `watch` command handler fetches the pending exercises. Going forward, the least recently updated exercises along with all the other exercises in a pending state are fetched. --- src/main.rs | 132 ++++++++++++++++++++++++++++------ tests/fixture/state/info.toml | 7 ++ tests/integration_tests.rs | 78 ++++++++++++++++++++ 3 files changed, 197 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index bf35e4fb..75a9cec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use notify::DebouncedEvent; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; use std::ffi::OsStr; use std::fs; -use std::io; +use std::io::{self, prelude::*}; use std::path::Path; use std::process::{Command, Stdio}; use std::sync::mpsc::channel; @@ -58,6 +58,45 @@ fn main() { SubCommand::with_name("list") .alias("l") .about("Lists the exercises available in rustlings") + .arg( + Arg::with_name("paths") + .long("paths") + .short("p") + .conflicts_with("names") + .help("Show only the paths of the exercises") + ) + .arg( + Arg::with_name("names") + .long("names") + .short("n") + .conflicts_with("paths") + .help("Show only the names of the exercises") + ) + .arg( + Arg::with_name("filter") + .long("filter") + .short("f") + .takes_value(true) + .empty_values(false) + .help( + "Provide a string to match the exercise names.\ + \nComma separated patterns are acceptable." + ) + ) + .arg( + Arg::with_name("unsolved") + .long("unsolved") + .short("u") + .conflicts_with("solved") + .help("Display only exercises not yet solved") + ) + .arg( + Arg::with_name("solved") + .long("solved") + .short("s") + .conflicts_with("unsolved") + .help("Display only exercises that have been solved") + ) ) .get_matches(); @@ -93,9 +132,51 @@ fn main() { let exercises = toml::from_str::(toml_str).unwrap().exercises; let verbose = matches.is_present("nocapture"); - if matches.subcommand_matches("list").is_some() { - exercises.iter().for_each(|e| println!("{}", e.name)); + // Handle the list command + if let Some(list_m) = matches.subcommand_matches("list") { + if ["paths", "names"].iter().all(|k| !list_m.is_present(k)) { + println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status"); + } + let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase(); + exercises.iter().for_each(|e| { + let fname = format!("{}", e.path.display()); + let filter_cond = filters + .split(',') + .filter(|f| f.trim().len() > 0) + .any(|f| e.name.contains(&f) || fname.contains(&f)); + let status = if e.looks_done() { "Done" } else { "Pending" }; + let solve_cond = { + (e.looks_done() && list_m.is_present("solved")) + || (!e.looks_done() && list_m.is_present("unsolved")) + || (!list_m.is_present("solved") && !list_m.is_present("unsolved")) + }; + if solve_cond && (filter_cond || !list_m.is_present("filter")) { + let line = if list_m.is_present("paths") { + format!("{}\n", fname) + } else if list_m.is_present("names") { + format!("{}\n", e.name) + } else { + format!("{:<17}\t{:<46}\t{:<7}\n", e.name, fname, status) + }; + // Somehow using println! leads to the binary panicking + // when its output is piped. + // So, we're handling a Broken Pipe error and exiting with 0 anyway + let stdout = std::io::stdout(); + { + let mut handle = stdout.lock(); + handle.write_all(line.as_bytes()).unwrap_or_else(|e| { + match e.kind() { + std::io::ErrorKind::BrokenPipe => std::process::exit(0), + _ => std::process::exit(1), + }; + }); + } + } + }); + std::process::exit(0); } + + // Handle the run command if let Some(ref matches) = matches.subcommand_matches("run") { let name = matches.value_of("name").unwrap(); @@ -123,13 +204,18 @@ fn main() { println!("{}", exercise.hint); } + // Handle the verify command if matches.subcommand_matches("verify").is_some() { verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); } + // Handle the watch command if matches.subcommand_matches("watch").is_some() { if let Err(e) = watch(&exercises, verbose) { - println!("Error: Could not watch your progess. Error message was {:?}.", e); + println!( + "Error: Could not watch your progess. Error message was {:?}.", + e + ); println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); std::process::exit(1); } @@ -138,24 +224,24 @@ fn main() { emoji = Emoji("🎉", "★") ); println!(); - println!("+----------------------------------------------------+"); - println!("| You made it to the Fe-nish line! |"); - println!("+-------------------------- ------------------------+"); + println!("+----------------------------------------------------+"); + println!("| You made it to the Fe-nish line! |"); + println!("+-------------------------- ------------------------+"); println!(" \\/ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); - println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); - println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); + println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); + println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); println!(); println!("We hope you enjoyed learning about the various aspects of Rust!"); @@ -223,7 +309,13 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { let filepath = b.as_path().canonicalize().unwrap(); let pending_exercises = exercises .iter() - .skip_while(|e| !filepath.ends_with(&e.path)); + .skip_while(|e| !filepath.ends_with(&e.path)) + // .filter(|e| filepath.ends_with(&e.path)) + .chain( + exercises + .iter() + .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)) + ); clear_screen(); match verify(pending_exercises, verbose) { Ok(_) => return Ok(()), diff --git a/tests/fixture/state/info.toml b/tests/fixture/state/info.toml index 7bfc697e..547b3a48 100644 --- a/tests/fixture/state/info.toml +++ b/tests/fixture/state/info.toml @@ -9,3 +9,10 @@ name = "pending_test_exercise" path = "pending_test_exercise.rs" mode = "test" hint = """""" + +[[exercises]] +name = "finished_exercise" +path = "finished_exercise.rs" +mode = "compile" +hint = """""" + diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 2baf9b86..f5211b64 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -181,3 +181,81 @@ fn run_single_test_success_without_output() { .code(0) .stdout(predicates::str::contains("THIS TEST TOO SHALL PAS").not()); } + +#[test] +fn run_rustlings_list() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list"]) + .current_dir("tests/fixture/success") + .assert() + .success(); +} + +#[test] +fn run_rustlings_list_conflicting_display_options() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list", "--names", "--paths"]) + .current_dir("tests/fixture/success") + .assert() + .failure(); +} + +#[test] +fn run_rustlings_list_conflicting_solve_options() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list", "--solved", "--unsolved"]) + .current_dir("tests/fixture/success") + .assert() + .failure(); +} + +#[test] +fn run_rustlings_list_no_pending() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list"]) + .current_dir("tests/fixture/success") + .assert() + .success() + .stdout(predicates::str::contains("Pending").not()); +} + +#[test] +fn run_rustlings_list_both_done_and_pending() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list"]) + .current_dir("tests/fixture/state") + .assert() + .success() + .stdout( + predicates::str::contains("Done") + .and(predicates::str::contains("Pending")) + ); +} + +#[test] +fn run_rustlings_list_without_pending() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list", "--solved"]) + .current_dir("tests/fixture/state") + .assert() + .success() + .stdout(predicates::str::contains("Pending").not()); +} + +#[test] +fn run_rustlings_list_without_done() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["list", "--unsolved"]) + .current_dir("tests/fixture/state") + .assert() + .success() + .stdout(predicates::str::contains("Done").not()); +} + From 9f988bfe29e1146cd7dc95c68dd6863e77433553 Mon Sep 17 00:00:00 2001 From: mokou Date: Sun, 17 Jan 2021 13:00:50 +0100 Subject: [PATCH 027/476] docs: Remove duplicate uninstallation section --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 987bb839..369bfab7 100644 --- a/README.md +++ b/README.md @@ -112,13 +112,6 @@ After every couple of sections, there will be a quiz that'll test your knowledge Once you've completed Rustlings, put your new knowledge to good use! Continue practicing your Rust skills by building your own projects, contributing to Rustlings, or finding other open-source projects to contribute to. -If you'd like to uninstall Rustlings, you can do so by invoking cargo and removing the rustlings directory: - -```bash -cargo uninstall rustlings -rm -r rustlings/ # or on Windows: rmdir /s rustlings -``` - ## Uninstalling Rustlings If you want to remove Rustlings from your system, there's two steps. First, you'll need to remove the exercises folder that the install script created From 15e71535f37cfaed36e22eb778728d186e2104ab Mon Sep 17 00:00:00 2001 From: Jean-Francois Chevrette Date: Thu, 21 Jan 2021 07:55:22 -0500 Subject: [PATCH 028/476] fix(from_str): test for error instead of unwrap/should_panic --- exercises/conversions/from_str.rs | 36 +++++++++++++------------------ 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 70ed1796..558a9033 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -11,15 +11,17 @@ struct Person { } // I AM NOT DONE + // Steps: -// 1. If the length of the provided string is 0, then return an error +// 1. If the length of the provided string is 0 an error should be returned // 2. Split the given string on the commas present in it -// 3. Extract the first element from the split operation and use it as the name -// 4. If the name is empty, then return an error +// 3. Only 2 elements should returned from the split, otherwise return an error +// 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::()`. -// If while parsing the age, something goes wrong, then return an error -// Otherwise, then return a Result of a Person object +// 5. 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 { type Err = String; fn from_str(s: &str) -> Result { @@ -48,50 +50,42 @@ mod tests { assert_eq!(p.age, 32); } #[test] - #[should_panic] fn missing_age() { - "John,".parse::().unwrap(); + assert!("John,".parse::().is_err()); } #[test] - #[should_panic] fn invalid_age() { - "John,twenty".parse::().unwrap(); + assert!("John,twenty".parse::().is_err()); } #[test] - #[should_panic] fn missing_comma_and_age() { - "John".parse::().unwrap(); + assert!("John".parse::().is_err()); } #[test] - #[should_panic] fn missing_name() { - ",1".parse::().unwrap(); + assert!(",1".parse::().is_err()); } #[test] - #[should_panic] fn missing_name_and_age() { - ",".parse::().unwrap(); + assert!(",".parse::().is_err()); } #[test] - #[should_panic] fn missing_name_and_invalid_age() { - ",one".parse::().unwrap(); + assert!(",one".parse::().is_err()); } #[test] - #[should_panic] fn trailing_comma() { - "John,32,".parse::().unwrap(); + assert!("John,32,".parse::().is_err()); } #[test] - #[should_panic] fn trailing_comma_and_some_string() { - "John,32,man".parse::().unwrap(); + assert!("John,32,man".parse::().is_err()); } } From 52bde71166740880da2206553df790d47cecba54 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 22 Jan 2021 12:11:33 +0000 Subject: [PATCH 029/476] 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 369bfab7..af97f556 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-72-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-73-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -250,6 +250,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Will Hayworth

🖋
Christian Zeller

🖋 + +
Jean-Francois Chevrette

🖋 💻 + From 6102e612fa3f6255cccea4c9016078f6ea007be0 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 22 Jan 2021 12:11:34 +0000 Subject: [PATCH 030/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 46e68ae5..ea3d7ca2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -673,6 +673,16 @@ "contributions": [ "content" ] + }, + { + "login": "jfchevrette", + "name": "Jean-Francois Chevrette", + "avatar_url": "https://avatars.githubusercontent.com/u/3001?v=4", + "profile": "https://github.com/jfchevrette", + "contributions": [ + "content", + "code" + ] } ], "contributorsPerLine": 8, From cddc1e86e7ec744ee644cc774a4887b1a0ded3e8 Mon Sep 17 00:00:00 2001 From: John Baber-Lucero Date: Sat, 30 Jan 2021 16:12:06 +0000 Subject: [PATCH 031/476] fix(info): Fix typo (#635) Co-authored-by: John Baber-Lucero --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 23c64917..f0fed934 100644 --- a/info.toml +++ b/info.toml @@ -284,7 +284,7 @@ hint = """ Rust has more than one type of struct. Three actually, all variants are used to package related data together. There are normal (or classic) structs. These are named collections of related data stored in fields. Tuple structs are basically just named tuples. -Finally, Unit structs. These don't have and fields and are useful for generics. +Finally, Unit structs. These don't have any fields and are useful for generics. In this exercise you need to complete and implement one of each kind. Read more about structs in The Book: https://doc.rust-lang.org/book/ch05-01-defining-structs.html""" From 75802c14b2dbfbbf65139608f19cb94dba6d7a2c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 30 Jan 2021 16:12:27 +0000 Subject: [PATCH 032/476] 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 af97f556..c2e598c1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-73-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-74-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -252,6 +252,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jean-Francois Chevrette

🖋 💻 +
John Baber-Lucero

🖋 From c1abd13b5c026643b5dddc85b3aa546ef75243d6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 30 Jan 2021 16:12:28 +0000 Subject: [PATCH 033/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index ea3d7ca2..9cdf6b08 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -683,6 +683,15 @@ "content", "code" ] + }, + { + "login": "jbaber", + "name": "John Baber-Lucero", + "avatar_url": "https://avatars.githubusercontent.com/u/1908117?v=4", + "profile": "https://github.com/jbaber", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From cc266d7d80b91e79df3f61984f231b7f1587218e Mon Sep 17 00:00:00 2001 From: Tal <3195851+tal-zvon@users.noreply.github.com> Date: Sun, 7 Feb 2021 04:22:13 -0700 Subject: [PATCH 034/476] fix(move_semantics4): Remove redundant "instead" (#640) --- exercises/move_semantics/move_semantics4.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index 6308c296..2a23c710 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -1,6 +1,6 @@ // move_semantics4.rs // Refactor this code so that instead of having `vec0` and creating the vector -// in `fn main`, we instead create it within `fn fill_vec` and transfer the +// in `fn main`, we create it within `fn fill_vec` and transfer the // freshly created vector from fill_vec to its caller. // Execute `rustlings hint move_semantics4` for hints! From 1f9d00685836cbf639a518b5612e7e16d669bf48 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:22:32 +0000 Subject: [PATCH 035/476] 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 c2e598c1..fe61f6f4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-74-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-75-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -253,6 +253,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jean-Francois Chevrette

🖋 💻
John Baber-Lucero

🖋 +
Tal

🖋 From f1d2b3a39a676ae25cc0e4fb18f582441bc239e2 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:22:33 +0000 Subject: [PATCH 036/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 9cdf6b08..6db7a29b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -692,6 +692,15 @@ "contributions": [ "content" ] + }, + { + "login": "tal-zvon", + "name": "Tal", + "avatar_url": "https://avatars.githubusercontent.com/u/3195851?v=4", + "profile": "https://github.com/tal-zvon", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 726805f064659f8cc2612974eb6d21690378cabc Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Tue, 9 Feb 2021 17:43:53 -0500 Subject: [PATCH 037/476] docs: Fixed grammar in contributing.md. --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d566df08..2ca0e341 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,12 +26,12 @@ isn't really that complicated since the bulk of the work is done by `rustc`. ### Adding an exercise -First step is to add the exercise! Call it `exercises/yourTopic/yourTopicN.rs`, make sure to +The first step is to add the exercise! Name the file `exercises/yourTopic/yourTopicN.rs`, make sure to put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`. -Next you want to make sure it runs when using `rustlings`. All exercises are stored in `info.toml`, under the `exercises` array. They're ordered by the order they're ran when using `rustlings verify`. +Next make sure it runs with `rustlings`. The exercise metadata is stored in `info.toml`, under the `exercises` array. The order of the `exercises` array determines the order the exercises are run by `rustlings verify`. -You want to make sure where in the file you add your exercise. If you're not sure, add it at the bottom and ask in your pull request. To add an exercise, edit the file like this: +Add the metadata for your exercise in the correct order in the `exercises` array. If you are unsure of the correct ordering, add it at the bottom and ask in your pull request. The exercise metadata should contain the following: ```diff ... + [[exercises]] From 2e84f34cf375fa3d12c73d1f28d68f0be9de3dc4 Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Tue, 9 Feb 2021 18:21:18 -0500 Subject: [PATCH 038/476] chore: Updated source to follow clippy suggestions. --- src/main.rs | 2 +- tests/integration_tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 75a9cec1..50e4a386 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,7 +142,7 @@ fn main() { let fname = format!("{}", e.path.display()); let filter_cond = filters .split(',') - .filter(|f| f.trim().len() > 0) + .filter(|f| !f.trim().is_empty()) .any(|f| e.name.contains(&f) || fname.contains(&f)); let status = if e.looks_done() { "Done" } else { "Pending" }; let solve_cond = { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index f5211b64..1bd3bf7e 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -131,7 +131,7 @@ fn all_exercises_require_confirmation() { file.read_to_string(&mut s).unwrap(); s }; - source.matches("// I AM NOT DONE").next().expect(&format!( + source.matches("// I AM NOT DONE").next().unwrap_or_else(|| panic!( "There should be an `I AM NOT DONE` annotation in {:?}", path )); From d65b4a9a93477745e206de11e1634ffe3cb3a6e6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 10 Feb 2021 09:36:47 +0000 Subject: [PATCH 039/476] 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 fe61f6f4..9e617eba 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-75-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-76-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -254,6 +254,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Jean-Francois Chevrette

🖋 💻
John Baber-Lucero

🖋
Tal

🖋 +
apogeeoak

🖋 💻 From f5158ece1a9d9896f089a352f8a2bd7502890864 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 10 Feb 2021 09:36:48 +0000 Subject: [PATCH 040/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6db7a29b..c4e68a15 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -701,6 +701,16 @@ "contributions": [ "content" ] + }, + { + "login": "apogeeoak", + "name": "apogeeoak", + "avatar_url": "https://avatars.githubusercontent.com/u/59737221?v=4", + "profile": "https://github.com/apogeeoak", + "contributions": [ + "content", + "code" + ] } ], "contributorsPerLine": 8, From b29ea17ea94d1862114af2cf5ced0e09c197dc35 Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Wed, 10 Feb 2021 18:03:29 -0500 Subject: [PATCH 041/476] feat: Added iterators5.rs exercise. --- .../standard_library_types/iterators5.rs | 113 ++++++++++++++++++ info.toml | 15 +++ 2 files changed, 128 insertions(+) create mode 100644 exercises/standard_library_types/iterators5.rs diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs new file mode 100644 index 00000000..65c50e62 --- /dev/null +++ b/exercises/standard_library_types/iterators5.rs @@ -0,0 +1,113 @@ +// iterators5.rs + +// Rustling progress is 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 number of exercises with a given progress. These counting +// functions use imperative style for loops. Recreate this counting +// functionality using iterators. +// Execute `rustlings hint iterators5` for hints. +// +// Make the code compile and the tests pass. + +// I AM NOT DONE + +use std::collections::HashMap; + +#[derive(PartialEq, Eq)] +enum Progress { + None, + Some, + Complete, +} + +fn count_for(map: &HashMap, value: Progress) -> usize { + let mut count = 0; + for val in map.values() { + if val == &value { + count += 1; + } + } + count +} + +fn count(map: &HashMap, value: Progress) -> usize { +} + +fn count_stack_for(stack: &[HashMap], value: Progress) -> usize { + let mut count = 0; + for map in stack { + for val in map.values() { + if val == &value { + count += 1; + } + } + } + count +} + +fn count_stack(stack: &[HashMap], value: Progress) -> usize { +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn count_complete() { + let map = get_map(); + assert_eq!(3, count(&map, Progress::Complete)); + } + + #[test] + fn count_equals_for() { + let map = get_map(); + assert_eq!( + count_for(&map, Progress::Complete), + count(&map, Progress::Complete) + ); + } + + #[test] + fn count_stack_complete() { + let stack = get_map_stack(); + assert_eq!(6, count_stack(&stack, Progress::Complete)); + } + + #[test] + fn count_stack_equals_for() { + let stack = get_map_stack(); + assert_eq!( + count_stack_for(&stack, Progress::Complete), + count_stack(&stack, Progress::Complete) + ); + } + + fn get_map() -> HashMap { + use Progress::*; + + let mut map = HashMap::new(); + map.insert(String::from("variables1"), Complete); + map.insert(String::from("functions1"), Complete); + map.insert(String::from("hashmap1"), Complete); + map.insert(String::from("arc1"), Some); + map.insert(String::from("as_ref_mut"), None); + map.insert(String::from("from_str"), None); + + map + } + + fn get_map_stack() -> Vec> { + use Progress::*; + + let map = get_map(); + + let mut other = HashMap::new(); + other.insert(String::from("variables2"), Complete); + other.insert(String::from("functions2"), Complete); + other.insert(String::from("if1"), Complete); + other.insert(String::from("from_into"), None); + other.insert(String::from("try_from_into"), None); + + vec![map, other] + } +} diff --git a/info.toml b/info.toml index f0fed934..646bb5a5 100644 --- a/info.toml +++ b/info.toml @@ -741,6 +741,21 @@ a mutable variable. Or, you might write code utilizing recursion and a match clause. In Rust you can take another functional approach, computing the factorial elegantly with ranges and iterators.""" +[[exercises]] +name = "iterators5" +path = "exercises/standard_library_types/iterators5.rs" +mode = "test" +hint = """ +The documentation for the std::iter::Iterator trait contains numerous methods +that would be helpful here. + +Return 0 from count_stack to make the code compile in order to test count. + +The stack variable in count_stack 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_stack function.""" + # THREADS [[exercises]] From baf4ba175ba6eb92989e3dd54ecbec4bedc9a863 Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Thu, 11 Feb 2021 21:24:32 -0500 Subject: [PATCH 042/476] fix(iterators2): Moved errors out of tests. Closes #359 --- .../standard_library_types/iterators2.rs | 38 ++++++++++++------- info.toml | 19 +++++----- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/exercises/standard_library_types/iterators2.rs b/exercises/standard_library_types/iterators2.rs index 84d14ae6..87b4eaa1 100644 --- a/exercises/standard_library_types/iterators2.rs +++ b/exercises/standard_library_types/iterators2.rs @@ -1,28 +1,41 @@ // iterators2.rs -// In this module, you'll learn some of the unique advantages that iterators can offer. -// Step 1. Complete the `capitalize_first` function to pass the first two cases. -// Step 2. Apply the `capitalize_first` function to a vector of strings. -// Ensure that it returns a vector of strings as well. -// Step 3. Apply the `capitalize_first` function again to a list. -// Try to ensure it returns a single string. +// In this exercise, you'll learn some of the unique advantages that iterators +// can offer. Follow the steps to complete the exercise. // As always, there are hints if you execute `rustlings hint iterators2`! // I AM NOT DONE +// Step 1. +// Complete the `capitalize_first` function. +// "hello" -> "Hello" pub fn capitalize_first(input: &str) -> String { let mut c = input.chars(); match c.next() { None => String::new(), - Some(first) => first.collect::() + c.as_str(), + Some(first) => ???, } } +// Step 2. +// Apply the `capitalize_first` function to a slice of string slices. +// Return a vector of strings. +// ["hello", "world"] -> ["Hello", "World"] +pub fn capitalize_words_vector(words: &[&str]) -> Vec { + vec![] +} + +// Step 3. +// Apply the `capitalize_first` function again to a slice of string slices. +// Return a single string. +// ["hello", " ", "world"] -> "Hello World" +pub fn capitalize_words_string(words: &[&str]) -> String { + String::new() +} + #[cfg(test)] mod tests { use super::*; - // Step 1. - // Tests that verify your `capitalize_first` function implementation #[test] fn test_success() { assert_eq!(capitalize_first("hello"), "Hello"); @@ -33,18 +46,15 @@ mod tests { assert_eq!(capitalize_first(""), ""); } - // Step 2. #[test] fn test_iterate_string_vec() { let words = vec!["hello", "world"]; - let capitalized_words: Vec = // TODO - assert_eq!(capitalized_words, ["Hello", "World"]); + assert_eq!(capitalize_words_vector(&words), ["Hello", "World"]); } #[test] fn test_iterate_into_string() { let words = vec!["hello", " ", "world"]; - let capitalized_words = // TODO - assert_eq!(capitalized_words, "Hello World"); + assert_eq!(capitalize_words_string(&words), "Hello World"); } } diff --git a/info.toml b/info.toml index f0fed934..5570b01c 100644 --- a/info.toml +++ b/info.toml @@ -704,21 +704,20 @@ path = "exercises/standard_library_types/iterators2.rs" mode = "test" hint = """ Step 1 -You need to call something on `first` before it can be collected -Currently its type is `char`. Have a look at the methods that are available on that type: +The variable `first` is a `char`. It needs to be capitalized and added to the +remaining characters in `c` in order to return the correct `String`. +The remaining characters in `c` can be viewed as a string slice using the +`as_str` method. +The documentation for `char` contains many useful methods. https://doc.rust-lang.org/std/primitive.char.html - Step 2 -First you'll need to turn the Vec into an iterator -Then you'll need to apply your function unto each item in the vector -P.s. Don't forget to collect() at the end! - +Create an iterator from the slice. Transform the iterated values by applying +the `capitalize_first` function. Remember to collect the iterator. Step 3. -This is very similar to the previous test. The only real change is that you will need to -alter the type that collect is coerced into. For a bonus you could try doing this with a -turbofish""" +This is surprising similar to the previous solution. Collect is very powerful +and very general. Rust just needs to know the desired type.""" [[exercises]] name = "iterators3" From c6712dfccd1a093e590ad22bbc4f49edc417dac0 Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Fri, 12 Feb 2021 15:36:53 -0500 Subject: [PATCH 043/476] fix(iterators3): Enabled iterators3.rs to run without commented out tests. --- .../standard_library_types/iterators3.rs | 47 ++++++++++--------- info.toml | 12 +++-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/exercises/standard_library_types/iterators3.rs b/exercises/standard_library_types/iterators3.rs index 353cea62..8c66c05b 100644 --- a/exercises/standard_library_types/iterators3.rs +++ b/exercises/standard_library_types/iterators3.rs @@ -1,11 +1,10 @@ // iterators3.rs // This is a bigger exercise than most of the others! You can do it! // Here is your mission, should you choose to accept it: -// 1. Complete the divide function to get the first four tests to pass -// 2. Uncomment the last two tests and get them to pass by filling in -// values for `x` using `division_results`. +// 1. Complete the divide function to get the first four tests to pass. +// 2. Get the remaining tests to pass by completing the result_with_list and +// list_of_results functions. // Execute `rustlings hint iterators3` to get some hints! -// Have fun :-) // I AM NOT DONE @@ -21,16 +20,28 @@ pub struct NotDivisibleError { divisor: i32, } -// This function should calculate `a` divided by `b` if `a` is -// evenly divisible by b. -// Otherwise, it should return a suitable error. +// Calculate `a` divided by `b` if `a` is evenly divisible by `b`. +// Otherwise, return a suitable error. pub fn divide(a: i32, b: i32) -> Result {} +// Complete the function and return a value of the correct type so the test passes. +// Desired output: Ok([1, 11, 1426, 3]) +fn result_with_list() -> () { + let numbers = vec![27, 297, 38502, 81]; + let division_results = numbers.into_iter().map(|n| divide(n, 27)); +} + +// Complete the function and return a value of the correct type so the test passes. +// Desired output: [Ok(1), Ok(11), Ok(1426), Ok(3)] +fn list_of_results() -> () { + let numbers = vec![27, 297, 38502, 81]; + let division_results = numbers.into_iter().map(|n| divide(n, 27)); +} + #[cfg(test)] mod tests { use super::*; - // Tests that verify your `divide` function implementation #[test] fn test_success() { assert_eq!(divide(81, 9), Ok(9)); @@ -57,22 +68,16 @@ mod tests { assert_eq!(divide(0, 81), Ok(0)); } - // Iterator exercises using your `divide` function - /* #[test] - fn result_with_list() { - let numbers = vec![27, 297, 38502, 81]; - let division_results = numbers.into_iter().map(|n| divide(n, 27)); - let x //... Fill in here! - assert_eq!(format!("{:?}", x), "Ok([1, 11, 1426, 3])"); + fn test_result_with_list() { + assert_eq!(format!("{:?}", result_with_list()), "Ok([1, 11, 1426, 3])"); } #[test] - fn list_of_results() { - let numbers = vec![27, 297, 38502, 81]; - let division_results = numbers.into_iter().map(|n| divide(n, 27)); - let x //... Fill in here! - assert_eq!(format!("{:?}", x), "[Ok(1), Ok(11), Ok(1426), Ok(3)]"); + fn test_list_of_results() { + assert_eq!( + format!("{:?}", list_of_results()), + "[Ok(1), Ok(11), Ok(1426), Ok(3)]" + ); } - */ } diff --git a/info.toml b/info.toml index f0fed934..73c5672c 100644 --- a/info.toml +++ b/info.toml @@ -725,11 +725,15 @@ name = "iterators3" path = "exercises/standard_library_types/iterators3.rs" mode = "test" hint = """ -Minor hint: In each of the two cases in the match in main, you can create x with either -a 'turbofish' or by hinting the type of x to the compiler. You may try both. +The divide function needs to return the correct error when even division is not +possible. -Major hint: Have a look at the Iter trait and at the explanation of its collect function. -Especially the part about Result is interesting.""" +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.""" [[exercises]] name = "iterators4" From 5f7c89f85db1f33da01911eaa479c3a2d4721678 Mon Sep 17 00:00:00 2001 From: Jirka Kremser <535866+jkremser@users.noreply.github.com> Date: Sun, 21 Feb 2021 21:50:17 +0100 Subject: [PATCH 044/476] fix(from_str): Correct typos typos in the comments --- exercises/conversions/from_str.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 558a9033..41fccd7e 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -13,13 +13,13 @@ struct Person { // I AM NOT DONE // Steps: -// 1. If the length of the provided string is 0 an error should be returned +// 1. If the length of the provided string is 0, an error should be returned // 2. Split the given string on the commas present in it -// 3. Only 2 elements should returned from the split, otherwise return an error +// 3. Only 2 elements should be returned from the split, otherwise return an error // 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 +// with something like `"4".parse::()` +// 5. 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 91ee27f22bd3797a9db57e5fd430801c170c5db8 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 24 Feb 2021 15:03:26 -0600 Subject: [PATCH 045/476] fix: Spelling error --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 50e4a386..569aa4ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -213,7 +213,7 @@ fn main() { if matches.subcommand_matches("watch").is_some() { if let Err(e) = watch(&exercises, verbose) { println!( - "Error: Could not watch your progess. Error message was {:?}.", + "Error: Could not watch your progress. Error message was {:?}.", e ); println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); From 320de0d92184fc0c4467a8cb5ac4af3b8fdcde6e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 25 Feb 2021 10:20:53 +0000 Subject: [PATCH 046/476] 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 9e617eba..8f7feb76 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-76-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-77-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -255,6 +255,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
John Baber-Lucero

🖋
Tal

🖋
apogeeoak

🖋 💻 +
Larry Garfield

🖋 From 797e6d45c04c1833cbe608ca0c9af648e5373e25 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 25 Feb 2021 10:20:54 +0000 Subject: [PATCH 047/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c4e68a15..3c2a0bb3 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -711,6 +711,15 @@ "content", "code" ] + }, + { + "login": "Crell", + "name": "Larry Garfield", + "avatar_url": "https://avatars.githubusercontent.com/u/254863?v=4", + "profile": "http://www.garfieldtech.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 833df0b8b3bcc03df50f76f3b9ed15c5ffc60870 Mon Sep 17 00:00:00 2001 From: circumspect <40770208+circumspect@users.noreply.github.com> Date: Fri, 12 Mar 2021 14:26:57 +0000 Subject: [PATCH 048/476] chore: fix typo Co-authored-by: Chenkail <40770208+Chenkail@users.noreply.github.com> --- src/exercise.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index 7afa230a..18e8d5ab 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -235,7 +235,7 @@ path = "{}.rs""#, // Check that the exercise looks to be solved using self.state() // This is not the best way to check since - // the user can just remove the "I AM NOT DONE" string fromm the file + // the user can just remove the "I AM NOT DONE" string from the file // without actually having solved anything. // The only other way to truly check this would to compile and run // the exercise; which would be both costly and counterintuitive From 3f5abca21535537dfcef69adaf2b08df790e47fa Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:28:03 +0100 Subject: [PATCH 049/476] docs: add circumspect as a contributor * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3c2a0bb3..9aa0630a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -720,6 +720,15 @@ "contributions": [ "content" ] + }, + { + "login": "circumspect", + "name": "circumspect", + "avatar_url": "https://avatars.githubusercontent.com/u/40770208?v=4", + "profile": "https://github.com/circumspect", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index 8f7feb76..97790643 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-77-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-78-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -256,6 +256,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Tal

🖋
apogeeoak

🖋 💻
Larry Garfield

🖋 +
circumspect

🖋 From 5157f568753737bab860831d13fe342dec27b242 Mon Sep 17 00:00:00 2001 From: Cyrus Wyett <34195737+cjwyett@users.noreply.github.com> Date: Fri, 12 Mar 2021 14:38:28 +0000 Subject: [PATCH 050/476] chore: fix typo is however some --> are however some --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index f0fed934..b37306c3 100644 --- a/info.toml +++ b/info.toml @@ -295,7 +295,7 @@ path = "exercises/structs/structs2.rs" mode = "test" hint = """ Creating instances of structs is easy, all you need to do is assign some values to its fields. -There is however some shortcuts that can be taken when instantiating structs. +There are however some shortcuts that can be taken when instantiating structs. Have a look in The Book, to find out more: https://doc.rust-lang.org/stable/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax""" [[exercises]] From 815edb7003c58f60c6baecb7d91cd72614be7ad6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:39:40 +0100 Subject: [PATCH 051/476] docs: add cjwyett as a contributor (#666) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 9aa0630a..4eab3c6b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -729,6 +729,15 @@ "contributions": [ "content" ] + }, + { + "login": "cjwyett", + "name": "Cyrus Wyett", + "avatar_url": "https://avatars.githubusercontent.com/u/34195737?v=4", + "profile": "https://github.com/cjwyett", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index 97790643..ca99796f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-78-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-79-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -257,6 +257,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
apogeeoak

🖋 💻
Larry Garfield

🖋
circumspect

🖋 +
Cyrus Wyett

🖋 From 05a753fe6333d36dbee5f68c21dec04eacdc75df Mon Sep 17 00:00:00 2001 From: cadolphs Date: Fri, 12 Mar 2021 09:36:35 -0800 Subject: [PATCH 052/476] fix: add check to prevent naive implementation of is_international * fix(structs3): Add check to prevent naive implementation * chore(structs3): Add a missed newline after the test I added --- exercises/structs/structs3.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 06fcaf29..f18cc925 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -57,6 +57,16 @@ mod tests { assert!(package.is_international()); } + #[test] + fn create_local_package() { + let sender_country = String::from("Canada"); + let recipient_country = sender_country.clone(); + + let package = Package::new(sender_country, recipient_country, 1200); + + assert!(!package.is_international()); + } + #[test] fn calculate_transport_fees() { let sender_country = String::from("Spain"); From 04dbf03ace1bc7f23f5f98bb701cba8505954c39 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:37:58 +0100 Subject: [PATCH 053/476] docs: add cadolphs as a contributor (#667) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4eab3c6b..45ea4b75 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -738,6 +738,15 @@ "contributions": [ "content" ] + }, + { + "login": "cadolphs", + "name": "cadolphs", + "avatar_url": "https://avatars.githubusercontent.com/u/13894820?v=4", + "profile": "https://github.com/cadolphs", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index ca99796f..b958fae6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-79-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-80-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -258,6 +258,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Larry Garfield

🖋
circumspect

🖋
Cyrus Wyett

🖋 +
cadolphs

💻 From 96c56ab08a30835e9f4d2b6b83b75a0060726fbd Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Fri, 12 Mar 2021 14:04:29 -0500 Subject: [PATCH 054/476] chore: changed errors3 mode from test to compile --- info.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.toml b/info.toml index b37306c3..2068750a 100644 --- a/info.toml +++ b/info.toml @@ -470,7 +470,7 @@ and give it a try!""" [[exercises]] name = "errors3" path = "exercises/error_handling/errors3.rs" -mode = "test" +mode = "compile" hint = """ If other functions can return a `Result`, why shouldn't `main`?""" @@ -694,7 +694,7 @@ Step 2 & step 2.1: Very similar to the lines above and below. You've got this! Step 3: An iterator goes through all elements in a collection, but what if we've run out of -elements? What should we expect here? If you're stuck, take a look at +elements? What should we expect here? If you're stuck, take a look at https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. """ From 9f3e8c2dde645e5264c2d2200e68842b5f47bfa3 Mon Sep 17 00:00:00 2001 From: Darius Wiles Date: Sat, 13 Mar 2021 03:14:02 -0800 Subject: [PATCH 055/476] fix(structs3): reword heading comment (#664) --- exercises/structs/structs3.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index f18cc925..8d8b4710 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -1,7 +1,8 @@ // structs3.rs -// Structs contain more than simply some data, they can also have logic, in this -// exercise we have defined the Package struct and we want to test some logic attached to it, -// make the code compile and the tests pass! If you have issues execute `rustlings hint structs3` +// Structs contain data, but can also have logic. In this exercise we have +// defined the Package struct and we want to test some logic attached to it. +// Make the code compile and the tests pass! +// If you have issues execute `rustlings hint structs3` // I AM NOT DONE From ebdb66c7bfb6d687a14cc511a559a222e6fc5de4 Mon Sep 17 00:00:00 2001 From: Darius Wiles Date: Sat, 13 Mar 2021 03:14:44 -0800 Subject: [PATCH 056/476] fix(structs2): correct grammar in hint (#663) 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 057/476] 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 3bce2ef8d6a613f6601328b3679ec18256cefec9 Mon Sep 17 00:00:00 2001 From: Pascal H Date: Mon, 15 Mar 2021 09:14:12 +0100 Subject: [PATCH 058/476] chore: clarify collections documentation C++ `map` is more like BTreeMap. `unordered_map` in C++(11) is the equivalent of `HashMap` in Rust. (+ additional like for references). --- exercises/collections/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/collections/README.md b/exercises/collections/README.md index 9ded29a0..af87863b 100644 --- a/exercises/collections/README.md +++ b/exercises/collections/README.md @@ -14,7 +14,7 @@ structures that are used very often in Rust programs: * A *vector* allows you to store a variable number of values next to each other. * A *hash map* allows you to associate a value with a particular key. - You may also know this by the names *map* in C++, *dictionary* in - Python or an *associative array* in other languages. + You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), + [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. [Rust book chapter](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) From be9510539e84c869362f6cd3fa6f791d3e02a821 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 15 Mar 2021 09:14:41 +0100 Subject: [PATCH 059/476] docs: add hpwxf as a contributor (#671) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 45ea4b75..5239b29c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -747,6 +747,15 @@ "contributions": [ "code" ] + }, + { + "login": "hpwxf", + "name": "Pascal H.", + "avatar_url": "https://avatars.githubusercontent.com/u/26146722?v=4", + "profile": "https://www.haveneer.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index b958fae6..85bba46d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-80-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-81-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -260,6 +260,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Cyrus Wyett

🖋
cadolphs

💻 + +
Pascal H.

🖋 + From 0d894e6ff739943901e1ae8c904582e5c2f843bd Mon Sep 17 00:00:00 2001 From: Pascal H Date: Tue, 16 Mar 2021 10:14:25 +0100 Subject: [PATCH 060/476] fix(quiz3): Force an answer to Q2 (#672) Add also an example of unimplemented!() macro. --- exercises/quiz3.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/quiz3.rs b/exercises/quiz3.rs index a0cd3712..fae0eedb 100644 --- a/exercises/quiz3.rs +++ b/exercises/quiz3.rs @@ -24,6 +24,7 @@ mod tests { #[test] fn returns_twice_of_negative_numbers() { - // TODO write an assert for `times_two(-4)` + // TODO replace unimplemented!() with an assert for `times_two(-4)` + unimplemented!() } } From bef39b125961310b34b34871e480a82e82af4678 Mon Sep 17 00:00:00 2001 From: Mickael Fortunato Date: Thu, 18 Mar 2021 18:39:22 +0100 Subject: [PATCH 061/476] fix(collections): Naming exercises for vectors and hashmap --- exercises/collections/vec2.rs | 7 +------ info.toml | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index ec6cfc00..08b6bbf5 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -28,11 +28,6 @@ mod tests { let v: Vec = (1..).filter(|x| x % 2 == 0).take(5).collect(); let ans = vec_loop(v.clone()); - assert_eq!( - ans, - v.iter() - .map(|x| x * 2) - .collect::>() - ); + assert_eq!(ans, v.iter().map(|x| x * 2).collect::>()); } } diff --git a/info.toml b/info.toml index 2068750a..baae76af 100644 --- a/info.toml +++ b/info.toml @@ -359,7 +359,7 @@ each constant.""" # COLLECTIONS [[exercises]] -name = "collections1" +name = "vec1" path = "exercises/collections/vec1.rs" mode = "test" hint = """ @@ -373,7 +373,7 @@ of the Rust book to learn more. """ [[exercises]] -name = "collections2" +name = "vec2" path = "exercises/collections/vec2.rs" mode = "test" hint = """ @@ -383,7 +383,7 @@ Hint 2: Check the suggestion from the compiler error ;) """ [[exercises]] -name = "collections3" +name = "hashmap1" path = "exercises/collections/hashmap1.rs" mode = "test" hint = """ @@ -394,7 +394,7 @@ Hint 2: Number of fruits should be at least 5. And you have to put """ [[exercises]] -name = "collections4" +name = "hashmap2" path = "exercises/collections/hashmap2.rs" mode = "test" hint = """ From ab9995e76e10fb1159f9ca1f378e3e11838dc5bc Mon Sep 17 00:00:00 2001 From: Mickael Fortunato Date: Thu, 18 Mar 2021 18:45:01 +0100 Subject: [PATCH 062/476] doc: Update collections exercises instruction to match the standard naming --- exercises/collections/hashmap1.rs | 6 ++---- exercises/collections/hashmap2.rs | 6 ++---- exercises/collections/vec1.rs | 2 +- exercises/collections/vec2.rs | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/exercises/collections/hashmap1.rs b/exercises/collections/hashmap1.rs index b1dc0bbd..64b5a7f3 100644 --- a/exercises/collections/hashmap1.rs +++ b/exercises/collections/hashmap1.rs @@ -8,7 +8,7 @@ // // Make me compile and pass the tests! // -// Execute the command `rustlings hint collections3` if you need +// Execute the command `rustlings hint hashmap1` if you need // hints. // I AM NOT DONE @@ -39,8 +39,6 @@ mod tests { #[test] fn at_least_five_fruits() { let basket = fruit_basket(); - assert!(basket - .values() - .sum::() >= 5); + assert!(basket.values().sum::() >= 5); } } diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 7e25be7c..f865fe1c 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -9,7 +9,7 @@ // // Make me pass the tests! // -// Execute the command `rustlings hint collections4` if you need +// Execute the command `rustlings hint hashmap2` if you need // hints. // I AM NOT DONE @@ -75,9 +75,7 @@ mod tests { fn greater_than_eleven_fruits() { let mut basket = get_fruit_basket(); fruit_basket(&mut basket); - let count = basket - .values() - .sum::(); + let count = basket.values().sum::(); assert!(count > 11); } } diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index f6bc837c..b144fb94 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -2,7 +2,7 @@ // Your task is to create a `Vec` which holds the exact same elements // as in the array `a`. // Make me compile and pass the test! -// Execute the command `rustlings hint collections1` if you need hints. +// Execute the command `rustlings hint vec1` if you need hints. // I AM NOT DONE diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index 08b6bbf5..6595e401 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -4,7 +4,7 @@ // // Make me pass the test! // -// Execute the command `rustlings hint collections2` if you need +// Execute the command `rustlings hint vec2` if you need // hints. // I AM NOT DONE From 8d62a9963708dbecd9312e8bcc4b47049c72d155 Mon Sep 17 00:00:00 2001 From: Matt Lebl Date: Fri, 19 Mar 2021 02:16:07 -0700 Subject: [PATCH 063/476] feat: Replace emojis when NO_EMOJI env variable present --- src/exercise.rs | 7 ++++++- src/ui.rs | 44 ++++++++++++++++++++++++++++++++++---------- src/verify.rs | 15 +++++++++++++-- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 18e8d5ab..2c5d835e 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -1,3 +1,4 @@ +use std::env; use regex::Regex; use serde::Deserialize; use std::fmt::{self, Display, Formatter}; @@ -126,8 +127,12 @@ name = "{}" path = "{}.rs""#, self.name, self.name, self.name ); + let cargo_toml_error_msg = match env::var("NO_EMOJI").is_ok() { + true => "Failed to write Clippy Cargo.toml file.", + false => "Failed to write 📎 Clippy 📎 Cargo.toml file." + }; fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml) - .expect("Failed to write 📎 Clippy 📎 Cargo.toml file."); + .expect(cargo_toml_error_msg); // To support the ability to run the clipy exercises, build // an executable, in addition to running clippy. With a // compilation failure, this would silently fail. But we expect diff --git a/src/ui.rs b/src/ui.rs index 38cbaa40..7ab87546 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,23 +1,47 @@ macro_rules! warn { ($fmt:literal, $ex:expr) => {{ + use std::env; use console::{style, Emoji}; let formatstr = format!($fmt, $ex); - println!( - "{} {}", - style(Emoji("⚠️ ", "!")).red(), - style(formatstr).red() - ); + match env::var("NO_EMOJI").is_ok() { + true => { + println!( + "{} {}", + style("!").red(), + style(formatstr).red() + ); + }, + false => { + println!( + "{} {}", + style(Emoji("⚠️ ", "!")).red(), + style(formatstr).red() + ); + } + } }}; } macro_rules! success { ($fmt:literal, $ex:expr) => {{ + use std::env; use console::{style, Emoji}; let formatstr = format!($fmt, $ex); - println!( - "{} {}", - style(Emoji("✅", "✓")).green(), - style(formatstr).green() - ); + match env::var("NO_EMOJI").is_ok() { + true => { + println!( + "{} {}", + style("✓").green(), + style(formatstr).green() + ); + }, + false => { + println!( + "{} {}", + style(Emoji("✅", "✓")).green(), + style(formatstr).green() + ); + } + } }}; } diff --git a/src/verify.rs b/src/verify.rs index 00e45c8c..04acfc68 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,3 +1,4 @@ +use std::env; use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; use indicatif::ProgressBar; @@ -137,14 +138,24 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option) -> State::Pending(context) => context, }; + let no_emoji = env::var("NO_EMOJI").is_ok(); + + let clippy_success_msg = match no_emoji { + true => "The code is compiling, and Clippy is happy!", + false => "The code is compiling, and 📎 Clippy 📎 is happy!" + }; + let success_msg = match exercise.mode { Mode::Compile => "The code is compiling!", Mode::Test => "The code is compiling, and the tests pass!", - Mode::Clippy => "The code is compiling, and 📎 Clippy 📎 is happy!", + Mode::Clippy => clippy_success_msg, }; println!(); - println!("🎉 🎉 {} 🎉 🎉", success_msg); + match no_emoji { + true => println!("~*~ {} ~*~", success_msg), + false => println!("🎉 🎉 {} 🎉 🎉", success_msg) + }; println!(); if let Some(output) = prompt_output { From 01e7f27aa6ab9ba868f3997c1e5f5d3aa0bac57a Mon Sep 17 00:00:00 2001 From: Matt Lebl Date: Sat, 20 Mar 2021 11:52:57 -0700 Subject: [PATCH 064/476] refactor: change from match to if for NO_EMOJI --- src/exercise.rs | 7 ++++--- src/ui.rs | 54 ++++++++++++++++++++++--------------------------- src/verify.rs | 16 ++++++++------- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 2c5d835e..3d2e38d1 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -127,9 +127,10 @@ name = "{}" path = "{}.rs""#, self.name, self.name, self.name ); - let cargo_toml_error_msg = match env::var("NO_EMOJI").is_ok() { - true => "Failed to write Clippy Cargo.toml file.", - false => "Failed to write 📎 Clippy 📎 Cargo.toml file." + let cargo_toml_error_msg = if env::var("NO_EMOJI").is_ok() { + "Failed to write Clippy Cargo.toml file." + } else { + "Failed to write 📎 Clippy 📎 Cargo.toml file." }; fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml) .expect(cargo_toml_error_msg); diff --git a/src/ui.rs b/src/ui.rs index 7ab87546..cb073372 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -3,21 +3,18 @@ macro_rules! warn { use std::env; use console::{style, Emoji}; let formatstr = format!($fmt, $ex); - match env::var("NO_EMOJI").is_ok() { - true => { - println!( - "{} {}", - style("!").red(), - style(formatstr).red() - ); - }, - false => { - println!( - "{} {}", - style(Emoji("⚠️ ", "!")).red(), - style(formatstr).red() - ); - } + if env::var("NO_EMOJI").is_ok() { + println!( + "{} {}", + style("!").red(), + style(formatstr).red() + ); + } else { + println!( + "{} {}", + style(Emoji("⚠️ ", "!")).red(), + style(formatstr).red() + ); } }}; } @@ -27,21 +24,18 @@ macro_rules! success { use std::env; use console::{style, Emoji}; let formatstr = format!($fmt, $ex); - match env::var("NO_EMOJI").is_ok() { - true => { - println!( - "{} {}", - style("✓").green(), - style(formatstr).green() - ); - }, - false => { - println!( - "{} {}", - style(Emoji("✅", "✓")).green(), - style(formatstr).green() - ); - } + if env::var("NO_EMOJI").is_ok() { + println!( + "{} {}", + style("✓").green(), + style(formatstr).green() + ); + } else { + println!( + "{} {}", + style(Emoji("✅", "✓")).green(), + style(formatstr).green() + ); } }}; } diff --git a/src/verify.rs b/src/verify.rs index 04acfc68..7a0e9ccd 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -140,9 +140,10 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option) -> let no_emoji = env::var("NO_EMOJI").is_ok(); - let clippy_success_msg = match no_emoji { - true => "The code is compiling, and Clippy is happy!", - false => "The code is compiling, and 📎 Clippy 📎 is happy!" + let clippy_success_msg = if no_emoji { + "The code is compiling, and Clippy is happy!" + } else { + "The code is compiling, and 📎 Clippy 📎 is happy!" }; let success_msg = match exercise.mode { @@ -152,10 +153,11 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option) -> }; println!(); - match no_emoji { - true => println!("~*~ {} ~*~", success_msg), - false => println!("🎉 🎉 {} 🎉 🎉", success_msg) - }; + if no_emoji { + println!("~*~ {} ~*~", success_msg) + } else { + println!("🎉 🎉 {} 🎉 🎉", success_msg) + } println!(); if let Some(output) = prompt_output { From 3df094713f4546745d4a9ea75cd75cba62473067 Mon Sep 17 00:00:00 2001 From: Rod Elias Date: Sat, 20 Mar 2021 17:12:49 -0300 Subject: [PATCH 065/476] chore: capitalize `c` letter By capitalizing the `c` letter it makes clear that we're talking about the C programming language. --- exercises/structs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/structs/README.md b/exercises/structs/README.md index d2d7dc24..72e0061b 100644 --- a/exercises/structs/README.md +++ b/exercises/structs/README.md @@ -1,6 +1,6 @@ ### Structs -Rust has three struct types: a classic c struct, a tuple struct, and a unit struct. +Rust has three struct types: a classic C struct, a tuple struct, and a unit struct. #### Book Sections From 550c4293ed269a7d888c384076ba247662af58c3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 20 Mar 2021 21:13:35 +0100 Subject: [PATCH 066/476] docs: add chapeupreto as a contributor (#678) * docs: update README.md [skip ci] * docs: update .all-contributorsrc [skip ci] Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5239b29c..ccce9476 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -756,6 +756,15 @@ "contributions": [ "content" ] + }, + { + "login": "chapeupreto", + "name": "Rod Elias", + "avatar_url": "https://avatars.githubusercontent.com/u/834048?v=4", + "profile": "https://twitter.com/chapeupreto", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, diff --git a/README.md b/README.md index 85bba46d..995b4258 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-81-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-82-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -262,6 +262,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pascal H.

🖋 +
Rod Elias

🖋 From 8dc587b01ab2e49a06308de29541330ff83dc371 Mon Sep 17 00:00:00 2001 From: marisa Date: Sun, 21 Mar 2021 16:34:21 +0100 Subject: [PATCH 067/476] chore: Update install URLs --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 995b4258..5871e3dc 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ You will need to have Rust installed. You can get it by visiting https://rustup. Just run: ```bash -curl -L https://git.io/rustlings | bash +curl -L https://git.io/install-rustlings | bash # Or if you want it to be installed to a different path: -curl -L https://git.io/rustlings | bash -s mypath/ +curl -L https://git.io/install-rustlings | bash -s mypath/ ``` This will install Rustlings and give you access to the `rustlings` command. Run it to get started! @@ -42,7 +42,7 @@ Set-ExecutionPolicy RemoteSigned Then, you can run: ```ps -Start-BitsTransfer -Source https://git.io/rustlings-win -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 +Start-BitsTransfer -Source https://git.io/install-rustlings-win -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 ``` To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. From c163011cc0e3b0d9eaae7ae51aadba1cf9a2226e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 12:37:01 +0000 Subject: [PATCH 068/476] 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 5871e3dc..75e298fb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-82-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-83-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -263,6 +263,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pascal H.

🖋
Rod Elias

🖋 +
Matt Lebl

💻 From 2a6e4dc8a65a1658f55edc5fe63854197839b358 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 22 Mar 2021 12:37:02 +0000 Subject: [PATCH 069/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index ccce9476..4726b643 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -765,6 +765,15 @@ "contributions": [ "content" ] + }, + { + "login": "blerchy", + "name": "Matt Lebl", + "avatar_url": "https://avatars.githubusercontent.com/u/2555355?v=4", + "profile": "https://github.com/blerchy", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From a02b27975018f69c51147f5f8d9638a5f4e26811 Mon Sep 17 00:00:00 2001 From: marisa Date: Tue, 23 Mar 2021 09:10:40 +0100 Subject: [PATCH 070/476] chore: Provide a working Windows installation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75e298fb..b453bf41 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Set-ExecutionPolicy RemoteSigned Then, you can run: ```ps -Start-BitsTransfer -Source https://git.io/install-rustlings-win -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 +Start-BitsTransfer -Source https://git.io/JTL5v -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 ``` To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. From a6509cc4d545d8825f01ddf7ee37823b372154dd Mon Sep 17 00:00:00 2001 From: Ignacio Le Fluk Date: Sun, 4 Apr 2021 03:43:25 -0400 Subject: [PATCH 071/476] fix(functions3): improve function argument type (#687) --- exercises/functions/functions3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index e3c1bf73..ed5f839f 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -7,7 +7,7 @@ fn main() { call_me(); } -fn call_me(num: i32) { +fn call_me(num: u32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } From aec2c65c632c94793d23fbb1fb826dd78e59ffdf Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 07:43:50 +0000 Subject: [PATCH 072/476] 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 b453bf41..479a307c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-83-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-84-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -264,6 +264,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pascal H.

🖋
Rod Elias

🖋
Matt Lebl

💻 +
Ignacio Le Fluk

🖋 From 2193fff4bb5e6becee03b1e9c37ee5069e6c9138 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 07:43:51 +0000 Subject: [PATCH 073/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4726b643..b0975cfe 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -774,6 +774,15 @@ "contributions": [ "code" ] + }, + { + "login": "flakolefluk", + "name": "Ignacio Le Fluk", + "avatar_url": "https://avatars.githubusercontent.com/u/11986564?v=4", + "profile": "http://flakolefluk.dev", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 2e93a588e0abe8badb7eafafb9e7d073c2be5df8 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 4 Apr 2021 00:04:03 -0500 Subject: [PATCH 074/476] fix: use trait objects for try_from_into Use `Box` to allow solutions to use `?` to propagate errors. In the tests, explicitly check `is_ok()` instead of trying to force the error type to `String` (or other `PartialEq` type) using `assert_eq!()`. --- exercises/conversions/try_from_into.rs | 40 ++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index e405c3f4..c0b5d986 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -3,6 +3,7 @@ // instead of the target type itself. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html use std::convert::{TryFrom, TryInto}; +use std::error; #[derive(Debug, PartialEq)] struct Color { @@ -24,19 +25,19 @@ struct Color { // Tuple implementation impl TryFrom<(i16, i16, i16)> for Color { - type Error = String; + type Error = Box; fn try_from(tuple: (i16, i16, i16)) -> Result {} } // Array implementation impl TryFrom<[i16; 3]> for Color { - type Error = String; + type Error = Box; fn try_from(arr: [i16; 3]) -> Result {} } // Slice implementation impl TryFrom<&[i16]> for Color { - type Error = String; + type Error = Box; fn try_from(slice: &[i16]) -> Result {} } @@ -76,41 +77,43 @@ mod tests { } #[test] fn test_tuple_correct() { - let c: Result = (183, 65, 14).try_into(); + let c: Result = (183, 65, 14).try_into(); + assert!(c.is_ok()); assert_eq!( - c, - Ok(Color { + c.unwrap(), + Color { red: 183, green: 65, blue: 14 - }) + } ); } #[test] fn test_array_out_of_range_positive() { - let c: Result = [1000, 10000, 256].try_into(); + let c: Result = [1000, 10000, 256].try_into(); assert!(c.is_err()); } #[test] fn test_array_out_of_range_negative() { - let c: Result = [-10, -256, -1].try_into(); + let c: Result = [-10, -256, -1].try_into(); assert!(c.is_err()); } #[test] fn test_array_sum() { - let c: Result = [-1, 255, 255].try_into(); + let c: Result = [-1, 255, 255].try_into(); assert!(c.is_err()); } #[test] fn test_array_correct() { - let c: Result = [183, 65, 14].try_into(); + let c: Result = [183, 65, 14].try_into(); + assert!(c.is_ok()); assert_eq!( - c, - Ok(Color { + c.unwrap(), + Color { red: 183, green: 65, blue: 14 - }) + } ); } #[test] @@ -131,14 +134,15 @@ mod tests { #[test] fn test_slice_correct() { let v = vec![183, 65, 14]; - let c: Result = Color::try_from(&v[..]); + let c: Result = Color::try_from(&v[..]); + assert!(c.is_ok()); assert_eq!( - c, - Ok(Color { + c.unwrap(), + Color { red: 183, green: 65, blue: 14 - }) + } ); } #[test] From c3e7b831786c9172ed8bd5d150f3c432f242fba9 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 4 Apr 2021 18:43:38 -0500 Subject: [PATCH 075/476] fix: use trait objects for from_str Use `Box` to allow solutions to use `?` to propagate errors. --- exercises/conversions/from_str.rs | 3 ++- info.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 41fccd7e..4beebacd 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -2,6 +2,7 @@ // Additionally, upon implementing FromStr, you can use the `parse` method // on strings to generate an object of the implementor type. // You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html +use std::error; use std::str::FromStr; #[derive(Debug)] @@ -23,7 +24,7 @@ struct Person { // If everything goes well, then return a Result of a Person object impl FromStr for Person { - type Err = String; + type Err = Box; fn from_str(s: &str) -> Result { } } diff --git a/info.toml b/info.toml index 2068750a..4a1d3aa3 100644 --- a/info.toml +++ b/info.toml @@ -884,5 +884,5 @@ path = "exercises/conversions/from_str.rs" mode = "test" hint = """ The implementation of FromStr should return an Ok with a Person object, -or an Err with a string if the string is not valid. +or an Err with an error if the string is not valid. This is almost like the `try_from_into` exercise.""" From 1ad20d94ff6982e66561d03727e52f04ffa8756b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 5 Apr 2021 11:27:16 +0000 Subject: [PATCH 076/476] 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 479a307c..6ffef489 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-84-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-85-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -265,6 +265,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Rod Elias

🖋
Matt Lebl

💻
Ignacio Le Fluk

🖋 +
Taylor Yu

💻 🖋 From 1a6a725f882ac25b4ed12cd960fdc3aad9b80eb3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 5 Apr 2021 11:27:17 +0000 Subject: [PATCH 077/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b0975cfe..c7f10be4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -783,6 +783,16 @@ "contributions": [ "content" ] + }, + { + "login": "tlyu", + "name": "Taylor Yu", + "avatar_url": "https://avatars.githubusercontent.com/u/431873?v=4", + "profile": "https://github.com/tlyu", + "contributions": [ + "code", + "content" + ] } ], "contributorsPerLine": 8, From b790bafc02b6cbeab928a5ddeba30ed8b111a817 Mon Sep 17 00:00:00 2001 From: WowSuchRicky Date: Fri, 9 Apr 2021 14:08:02 -0700 Subject: [PATCH 078/476] Rename lichi to lychee in the fruit example --- exercises/collections/hashmap2.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 7e25be7c..cacdf203 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -4,7 +4,7 @@ // represents the name of the fruit and the value represents how many // of that particular fruit is in the basket. You have to put *MORE // THAN 11* fruits in the basket. Three types of fruits - Apple (4), -// Mango (2) and Lichi (5) are already given in the basket. You are +// Mango (2) and Lychee (5) are already given in the basket. You are // not allowed to insert any more of these fruits! // // Make me pass the tests! @@ -21,7 +21,7 @@ enum Fruit { Apple, Banana, Mango, - Lichi, + Lychee, Pineapple, } @@ -30,7 +30,7 @@ fn fruit_basket(basket: &mut HashMap) { Fruit::Apple, Fruit::Banana, Fruit::Mango, - Fruit::Lichi, + Fruit::Lychee, Fruit::Pineapple, ]; @@ -49,7 +49,7 @@ mod tests { let mut basket = HashMap::::new(); basket.insert(Fruit::Apple, 4); basket.insert(Fruit::Mango, 2); - basket.insert(Fruit::Lichi, 5); + basket.insert(Fruit::Lychee, 5); basket } @@ -60,7 +60,7 @@ mod tests { fruit_basket(&mut basket); assert_eq!(*basket.get(&Fruit::Apple).unwrap(), 4); assert_eq!(*basket.get(&Fruit::Mango).unwrap(), 2); - assert_eq!(*basket.get(&Fruit::Lichi).unwrap(), 5); + assert_eq!(*basket.get(&Fruit::Lychee).unwrap(), 5); } #[test] From c0e3daacaf6850811df5bc57fa43e0f249d5cfa4 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sun, 18 Apr 2021 15:37:41 +0200 Subject: [PATCH 079/476] feat(list): added progress info Added a progress info at the bottom of the list for command: rustlings list closes #705 --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 569aa4ac..73647234 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,13 +138,19 @@ fn main() { println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status"); } let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase(); + let mut exercises_done: u16 = 0; exercises.iter().for_each(|e| { let fname = format!("{}", e.path.display()); let filter_cond = filters .split(',') .filter(|f| !f.trim().is_empty()) .any(|f| e.name.contains(&f) || fname.contains(&f)); - let status = if e.looks_done() { "Done" } else { "Pending" }; + let status = if e.looks_done() { + exercises_done = exercises_done + 1; + "Done" + } else { + "Pending" + }; let solve_cond = { (e.looks_done() && list_m.is_present("solved")) || (!e.looks_done() && list_m.is_present("unsolved")) @@ -173,6 +179,13 @@ fn main() { } } }); + let percentage_progress = exercises_done as f32 / exercises.len() as f32; + println!( + "Progress: You completed {} / {} exercises ({:.2} %).", + exercises_done, + exercises.len(), + percentage_progress + ); std::process::exit(0); } @@ -314,7 +327,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { .chain( exercises .iter() - .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)) + .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)), ); clear_screen(); match verify(pending_exercises, verbose) { From bd48544e25bb58f86fee1b1a5004e961996a3388 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sun, 18 Apr 2021 15:40:47 +0200 Subject: [PATCH 080/476] style: formatted files with rustfmt --- src/exercise.rs | 5 ++--- src/ui.rs | 16 ++++------------ src/verify.rs | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 3d2e38d1..e9d1c1c9 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -1,6 +1,6 @@ -use std::env; use regex::Regex; use serde::Deserialize; +use std::env; use std::fmt::{self, Display, Formatter}; use std::fs::{self, remove_file, File}; use std::io::Read; @@ -132,8 +132,7 @@ path = "{}.rs""#, } else { "Failed to write 📎 Clippy 📎 Cargo.toml file." }; - fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml) - .expect(cargo_toml_error_msg); + fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml).expect(cargo_toml_error_msg); // To support the ability to run the clipy exercises, build // an executable, in addition to running clippy. With a // compilation failure, this would silently fail. But we expect diff --git a/src/ui.rs b/src/ui.rs index cb073372..1ee46316 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,14 +1,10 @@ macro_rules! warn { ($fmt:literal, $ex:expr) => {{ - use std::env; use console::{style, Emoji}; + use std::env; let formatstr = format!($fmt, $ex); if env::var("NO_EMOJI").is_ok() { - println!( - "{} {}", - style("!").red(), - style(formatstr).red() - ); + println!("{} {}", style("!").red(), style(formatstr).red()); } else { println!( "{} {}", @@ -21,15 +17,11 @@ macro_rules! warn { macro_rules! success { ($fmt:literal, $ex:expr) => {{ - use std::env; use console::{style, Emoji}; + use std::env; let formatstr = format!($fmt, $ex); if env::var("NO_EMOJI").is_ok() { - println!( - "{} {}", - style("✓").green(), - style(formatstr).green() - ); + println!("{} {}", style("✓").green(), style(formatstr).green()); } else { println!( "{} {}", diff --git a/src/verify.rs b/src/verify.rs index 7a0e9ccd..b98598a8 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,7 +1,7 @@ -use std::env; use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; use indicatif::ProgressBar; +use std::env; // Verify that the provided container of Exercise objects // can be compiled and run without any failures. From e2c41903ad491df5c0c59c389e3f568dd2485611 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sun, 18 Apr 2021 16:07:30 +0200 Subject: [PATCH 081/476] docs: added hint for rustlings list command Added hint for `rustlings list` to the "Doing exercises" section. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6ffef489..19ec6ce4 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,11 @@ exercise: rustlings hint myExercise1 ``` +To check your progress, you can run the following command: +```bash +rustlings list +``` + ## Testing yourself After every couple of sections, there will be a quiz that'll test your knowledge on a bunch of sections at once. These quizzes are found in `exercises/quizN.rs`. From 1c6f7e4b7b9b3bd36f4da2bb2b69c549cc8bd913 Mon Sep 17 00:00:00 2001 From: Patrick Hintermayer Date: Mon, 19 Apr 2021 09:39:05 +0200 Subject: [PATCH 082/476] feat(list): updated progress percentage --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 73647234..3b7a1942 100644 --- a/src/main.rs +++ b/src/main.rs @@ -179,7 +179,7 @@ fn main() { } } }); - let percentage_progress = exercises_done as f32 / exercises.len() as f32; + let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0; println!( "Progress: You completed {} / {} exercises ({:.2} %).", exercises_done, From 2612edc133c8ec6e2c10c13ed9c86019ea6d27d9 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:09:30 +0000 Subject: [PATCH 083/476] 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 6ffef489..ed0095cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-85-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-86-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -266,6 +266,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Matt Lebl

💻
Ignacio Le Fluk

🖋
Taylor Yu

💻 🖋 +
Patrick Hintermayer

💻 From 63c942233e8e9fe1171e51acf35d8dc93897471b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:09:31 +0000 Subject: [PATCH 084/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c7f10be4..8621df10 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -793,6 +793,15 @@ "code", "content" ] + }, + { + "login": "Zerotask", + "name": "Patrick Hintermayer", + "avatar_url": "https://avatars.githubusercontent.com/u/20150243?v=4", + "profile": "https://zerotask.github.io", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 72aaa15e6ab4b72b3422f1c6356396e20a2a2bb8 Mon Sep 17 00:00:00 2001 From: Pete Pavlovski Date: Tue, 20 Apr 2021 12:15:49 +0300 Subject: [PATCH 085/476] fix(hashmap2): Update incorrect assertion (#660) The test description says "at least five types of fruit", but the test itself is checking for exactly five types of fruit, which was a bit misleading for newcomers like me :) A simple change from "==" to ">=" should do the trick and successfully check for the "at least" condition. --- exercises/collections/hashmap2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index c8698fed..0abe19ab 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -68,7 +68,7 @@ mod tests { let mut basket = get_fruit_basket(); fruit_basket(&mut basket); let count_fruit_kinds = basket.len(); - assert!(count_fruit_kinds == 5); + assert!(count_fruit_kinds >= 5); } #[test] From a941c69f09c7349ff578da348a075a146c1005b6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:16:15 +0000 Subject: [PATCH 086/476] 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 760565e2..10b7c1cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-86-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-87-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -272,6 +272,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Ignacio Le Fluk

🖋
Taylor Yu

💻 🖋
Patrick Hintermayer

💻 +
Pete Pavlovski

🖋 From bdf01aa174533d5908e83a7ed3113b62f4eb6fe3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:16:16 +0000 Subject: [PATCH 087/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 8621df10..0b490899 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -802,6 +802,15 @@ "contributions": [ "code" ] + }, + { + "login": "arthas168", + "name": "Pete Pavlovski", + "avatar_url": "https://avatars.githubusercontent.com/u/32264020?v=4", + "profile": "https://petkopavlovski.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From b4de6594380636817d13c2677ec6f472a964cf43 Mon Sep 17 00:00:00 2001 From: k12ish <45272873+k12ish@users.noreply.github.com> Date: Tue, 20 Apr 2021 10:18:05 +0100 Subject: [PATCH 088/476] fix(option2): Rename uninformative variables (#675) Renaming uninformative names like `optional_value`, `value`, `optional_values_vec` and `value` helps users distinguish between the two parts of the task. --- exercises/option/option2.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/option/option2.rs b/exercises/option/option2.rs index a1517d7c..c6b83ece 100644 --- a/exercises/option/option2.rs +++ b/exercises/option/option2.rs @@ -4,22 +4,22 @@ // I AM NOT DONE fn main() { - let optional_value = Some(String::from("rustlings")); + let optional_word = Some(String::from("rustlings")); // TODO: Make this an if let statement whose value is "Some" type - value = optional_value { - println!("the value of optional value is: {}", value); + word = optional_word { + println!("The word is: {}", word); } else { - println!("The optional value doesn't contain anything!"); + println!("The optional word doesn't contain anything"); } - let mut optional_values_vec: Vec> = Vec::new(); + let mut optional_integers_vec: Vec> = Vec::new(); for x in 1..10 { - optional_values_vec.push(Some(x)); + optional_integers_vec.push(Some(x)); } // TODO: make this a while let statement - remember that vector.pop also adds another layer of Option // You can stack `Option`'s into while let and if let - value = optional_values_vec.pop() { - println!("current value: {}", value); + integer = optional_integers_vec.pop() { + println!("current value: {}", integer); } } From 472f61485e49864d62901ee024ed5c8a18b861a0 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:18:22 +0000 Subject: [PATCH 089/476] 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 10b7c1cf..721c63a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-87-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-88-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -273,6 +273,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Taylor Yu

💻 🖋
Patrick Hintermayer

💻
Pete Pavlovski

🖋 +
k12ish

🖋 From 65cdc856aec4f86c7b513d2b85d3357e5a9b3a4f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:18:23 +0000 Subject: [PATCH 090/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0b490899..a2473872 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -811,6 +811,15 @@ "contributions": [ "content" ] + }, + { + "login": "k12ish", + "name": "k12ish", + "avatar_url": "https://avatars.githubusercontent.com/u/45272873?v=4", + "profile": "https://github.com/k12ish", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 6bd791f2f44aa7f0ad926df767f6b1fa8f12a9a9 Mon Sep 17 00:00:00 2001 From: Shao Yang Hong Date: Tue, 20 Apr 2021 17:19:24 +0800 Subject: [PATCH 091/476] fix(structs): Add 5.3 to structs/README (#652) Co-authored-by: Shao Yang Hong --- exercises/structs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/structs/README.md b/exercises/structs/README.md index 72e0061b..58e5a6a4 100644 --- a/exercises/structs/README.md +++ b/exercises/structs/README.md @@ -5,3 +5,4 @@ Rust has three struct types: a classic C struct, a tuple struct, and a unit stru #### Book Sections - [Structures](https://doc.rust-lang.org/book/ch05-01-defining-structs.html) +- [Method Syntax](https://doc.rust-lang.org/book/ch05-03-method-syntax.html) From fab2eb98333434079a3ace6c7d0aa31892bd49cb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:19:38 +0000 Subject: [PATCH 092/476] 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 721c63a0..2d2cb0ef 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-88-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-89-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -275,6 +275,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pete Pavlovski

🖋
k12ish

🖋 + +
Shao Yang Hong

🖋 + From eadd41a9ecb05e3278a988f752e77608ded136fa Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:19:39 +0000 Subject: [PATCH 093/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index a2473872..e820b426 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -820,6 +820,15 @@ "contributions": [ "content" ] + }, + { + "login": "hongshaoyang", + "name": "Shao Yang Hong", + "avatar_url": "https://avatars.githubusercontent.com/u/19281800?v=4", + "profile": "https://github.com/hongshaoyang", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 9c88ea91266c84901fd46496902610241dab3baf Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Tue, 20 Apr 2021 18:52:10 -0400 Subject: [PATCH 094/476] Improved iterators5.rs explanation. --- .../standard_library_types/iterators5.rs | 51 +++++++++++-------- info.toml | 11 ++-- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index 65c50e62..2d97bd46 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -1,11 +1,14 @@ // iterators5.rs -// Rustling progress is 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 number of exercises with a given progress. These counting -// functions use imperative style for loops. Recreate this counting -// functionality using iterators. -// Execute `rustlings hint iterators5` for hints. +// 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 +// number of exercises with a given progress. These counting functions use +// 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. // // Make the code compile and the tests pass. @@ -30,12 +33,14 @@ fn count_for(map: &HashMap, value: Progress) -> usize { count } -fn count(map: &HashMap, value: Progress) -> usize { +fn count_iterator(map: &HashMap, value: Progress) -> usize { + // map is a hashmap with String keys and Progress values. + // map = { "variables1": Complete, "from_str": None, ... } } -fn count_stack_for(stack: &[HashMap], value: Progress) -> usize { +fn count_collection_for(collection: &[HashMap], value: Progress) -> usize { let mut count = 0; - for map in stack { + for map in collection { for val in map.values() { if val == &value { count += 1; @@ -45,7 +50,10 @@ fn count_stack_for(stack: &[HashMap], value: Progress) -> usiz count } -fn count_stack(stack: &[HashMap], value: Progress) -> usize { +fn count_collection_iterator(collection: &[HashMap], value: Progress) -> usize { + // collection is a slice of hashmaps. + // collection = [{ "variables1": Complete, "from_str": None, ... }, + // { "variables2": Complete, ... }, ... ] } #[cfg(test)] @@ -55,7 +63,7 @@ mod tests { #[test] fn count_complete() { let map = get_map(); - assert_eq!(3, count(&map, Progress::Complete)); + assert_eq!(3, count_iterator(&map, Progress::Complete)); } #[test] @@ -63,22 +71,25 @@ mod tests { let map = get_map(); assert_eq!( count_for(&map, Progress::Complete), - count(&map, Progress::Complete) + count_iterator(&map, Progress::Complete) ); } #[test] - fn count_stack_complete() { - let stack = get_map_stack(); - assert_eq!(6, count_stack(&stack, Progress::Complete)); + fn count_collection_complete() { + let collection = get_vec_map(); + assert_eq!( + 6, + count_collection_iterator(&collection, Progress::Complete) + ); } #[test] - fn count_stack_equals_for() { - let stack = get_map_stack(); + fn count_collection_equals_for() { + let collection = get_vec_map(); assert_eq!( - count_stack_for(&stack, Progress::Complete), - count_stack(&stack, Progress::Complete) + count_collection_for(&collection, Progress::Complete), + count_collection_iterator(&collection, Progress::Complete) ); } @@ -96,7 +107,7 @@ mod tests { map } - fn get_map_stack() -> Vec> { + fn get_vec_map() -> Vec> { use Progress::*; let map = get_map(); diff --git a/info.toml b/info.toml index 646bb5a5..65f671ac 100644 --- a/info.toml +++ b/info.toml @@ -694,7 +694,7 @@ Step 2 & step 2.1: Very similar to the lines above and below. You've got this! Step 3: An iterator goes through all elements in a collection, but what if we've run out of -elements? What should we expect here? If you're stuck, take a look at +elements? What should we expect here? If you're stuck, take a look at https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas. """ @@ -749,12 +749,13 @@ hint = """ The documentation for the std::iter::Iterator trait contains numerous methods that would be helpful here. -Return 0 from count_stack to make the code compile in order to test count. +Return 0 from count_collection_iterator to make the code compile in order to +test count_iterator. -The stack variable in count_stack is a slice of HashMaps. It needs to be -converted into an iterator in order to use the iterator methods. +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_stack function.""" +The fold method can be useful in the count_collection_iterator function.""" # THREADS From 7928122fcef9ca7834d988b1ec8ca0687478beeb Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 20 Apr 2021 12:46:49 +0200 Subject: [PATCH 095/476] feat: Replace clap with argh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I’ve been wanting to do this for a while, but always procrastinated on it. We’ve been using Clap since the 2.0 rewrite, but Clap is known to be a fairly heavy library. Since Rustlings is usually peoples’ first contact with a Rust compilation, I think it’s in our best interests that this complation is as fast as possible. In effect, replacing Clap with the smaller, structopt-style `argh` reduces the amount of crates needing to be compiled from 82 to 60. I also think this makes the code way easier to read, we don’t need to use Clap’s methods anymore, but can switch over to using pure Rust methods, e.g., switches are booleans, options are Options or the like, and subcommands are just structs. --- Cargo.lock | 543 +++++++++++++++++------------------------------- Cargo.toml | 2 +- src/exercise.rs | 4 +- src/main.rs | 431 +++++++++++++++++++------------------- 4 files changed, 405 insertions(+), 575 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a4313e7..367881c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,22 +2,42 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.3" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" dependencies = [ "memchr", ] [[package]] -name = "ansi_term" -version = "0.11.0" +name = "argh" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "91792f088f87cdc7a2cfb1d617fa5ea18d7f1dc22ef0e1b5f82f3157cdc522be" dependencies = [ - "winapi 0.3.8", + "argh_derive", + "argh_shared", ] +[[package]] +name = "argh_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4eb0c0c120ad477412dc95a4ce31e38f2113e46bd13511253f79196ca68b067" +dependencies = [ + "argh_shared", + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "argh_shared" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "781f336cc9826dbaddb9754cb5db61e64cab4f69668bd19dcc4a0394a86f4cb1" + [[package]] name = "assert_cmd" version = "0.11.1" @@ -32,67 +52,49 @@ dependencies = [ [[package]] name = "atty" -version = "0.2.11" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ + "hermit-abi", "libc", - "termion", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "autocfg" -version = "0.1.4" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" -version = "1.0.4" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cfg-if" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] -name = "clap" -version = "2.33.0" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", -] +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clicolors-control" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" +checksum = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e" dependencies = [ "atty", "lazy_static", "libc", - "winapi 0.3.8", -] - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", + "winapi 0.3.9", ] [[package]] @@ -110,23 +112,22 @@ dependencies = [ "regex", "termios", "unicode-width", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "console" -version = "0.8.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b147390a412132d75d10dd3b7b175a69cf5fd95032f7503c7091b8831ba10242" +checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" dependencies = [ - "clicolors-control", "encode_unicode", "lazy_static", "libc", "regex", - "termios", + "terminal_size", "unicode-width", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] @@ -137,9 +138,9 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "encode_unicode" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "escargot" @@ -155,20 +156,21 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.5" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", + "winapi 0.3.9", ] [[package]] name = "float-cmp" -version = "0.4.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" +checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" dependencies = [ "num-traits", ] @@ -192,12 +194,6 @@ dependencies = [ "libc", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -220,13 +216,31 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + [[package]] name = "indicatif" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" dependencies = [ - "console 0.8.0", + "console 0.14.1", "lazy_static", "number_prefix", "parking_lot", @@ -235,9 +249,9 @@ dependencies = [ [[package]] name = "inotify" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e40d6fd5d64e2082e0c796495c8ef5ad667a96d03e5aaa0becfd9d47bcbfb8" +checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" dependencies = [ "bitflags", "inotify-sys", @@ -246,28 +260,36 @@ dependencies = [ [[package]] name = "inotify-sys" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" dependencies = [ "libc", ] +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" dependencies = [ "libc", - "winapi 0.2.8", ] [[package]] name = "itoa" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "kernel32-sys" @@ -281,52 +303,53 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.58" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "lock_api" -version = "0.2.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.6" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] name = "memchr" -version = "2.2.0" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "mio" -version = "0.6.19" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" dependencies = [ + "cfg-if 0.1.10", "fuchsia-zircon", "fuchsia-zircon-sys", "iovec", @@ -341,9 +364,9 @@ dependencies = [ [[package]] name = "mio-extras" -version = "2.0.5" +version = "2.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" +checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", "log", @@ -353,9 +376,9 @@ dependencies = [ [[package]] name = "miow" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" dependencies = [ "kernel32-sys", "net2", @@ -365,26 +388,26 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.33" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "libc", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "normalize-line-endings" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "notify" -version = "4.0.15" +version = "4.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80ae4a7688d1fab81c5bf19c64fc8db920be8d519ce6336ed4e7efe024724dbd" +checksum = "2599080e87c9bd051ddb11b10074f4da7b1223298df65d4c2ec5bcf309af1533" dependencies = [ "bitflags", "filetime", @@ -395,14 +418,14 @@ dependencies = [ "mio", "mio-extras", "walkdir", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "num-traits" -version = "0.2.8" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg", ] @@ -416,44 +439,36 @@ dependencies = [ "num-traits", ] -[[package]] -name = "numtoa" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" - [[package]] name = "parking_lot" -version = "0.8.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" dependencies = [ + "instant", "lock_api", "parking_lot_core", - "rustc_version", ] [[package]] name = "parking_lot_core" -version = "0.5.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ - "cfg-if", - "cloudabi", + "cfg-if 1.0.0", + "instant", "libc", - "rand", "redox_syscall", - "rustc_version", "smallvec", - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] name = "predicates" -version = "1.0.1" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e09015b0d3f5a0ec2d4428f7559bb7b3fff341b4e159fedd1d57fac8b939ff" +checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" dependencies = [ "difference", "float-cmp", @@ -464,15 +479,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06075c3a3e92559ff8929e7a280684489ea27fe44805174c3ebd9328dcb37178" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e63c4859013b38a76eca2414c64911fba30def9e3202ac461a2d22831220124" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" dependencies = [ "predicates-core", "treeline", @@ -480,189 +495,54 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "0.4.30" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "0.6.12" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg", - "libc", - "rand_chacha", - "rand_core 0.4.0", - "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.8", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg", - "rand_core 0.3.1", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.0", -] - -[[package]] -name = "rand_core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" - -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.0", - "winapi 0.3.8", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.0", - "rdrand", - "winapi 0.3.8", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg", - "rand_core 0.4.0", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" -version = "0.1.54" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" - -[[package]] -name = "redox_termios" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" dependencies = [ - "redox_syscall", + "bitflags", ] [[package]] name = "regex" -version = "1.1.6" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", - "utf8-ranges", ] [[package]] name = "regex-syntax" -version = "0.6.6" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" -dependencies = [ - "ucd-util", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "rustlings" version = "4.3.0" dependencies = [ + "argh", "assert_cmd", - "clap", "console 0.7.7", "glob", "indicatif", @@ -675,54 +555,39 @@ dependencies = [ [[package]] name = "ryu" -version = "0.2.8" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "same-file" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ "winapi-util", ] [[package]] name = "scopeguard" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.92" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.92" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", @@ -731,9 +596,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.39" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -748,21 +613,15 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "0.6.9" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" - -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "0.15.34" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ "proc-macro2", "quote", @@ -770,44 +629,24 @@ dependencies = [ ] [[package]] -name = "termion" -version = "1.5.2" +name = "terminal_size" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" +checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" dependencies = [ "libc", - "numtoa", - "redox_syscall", - "redox_termios", + "winapi 0.3.9", ] [[package]] name = "termios" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" +checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" dependencies = [ "libc", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -dependencies = [ - "lazy_static", -] - [[package]] name = "toml" version = "0.4.10" @@ -824,43 +663,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] -name = "ucd-util" -version = "0.1.3" +name = "unicode-segmentation" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" -version = "0.1.5" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" - -[[package]] -name = "utf8-ranges" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" - -[[package]] -name = "vec_map" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "walkdir" -version = "2.2.7" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.8", + "winapi 0.3.9", "winapi-util", ] @@ -872,9 +699,9 @@ checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", @@ -894,11 +721,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.8", + "winapi 0.3.9", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a0564c37..397eb996 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Marisa ", "Carol (Nichols || Goulding) String { } // The mode of the exercise. -#[derive(Deserialize, Copy, Clone)] +#[derive(Deserialize, Copy, Clone, Debug)] #[serde(rename_all = "lowercase")] pub enum Mode { // Indicates that the exercise should be compiled as a binary @@ -42,7 +42,7 @@ pub struct ExerciseList { // A representation of a rustlings exercise. // This is deserialized from the accompanying info.toml file -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub struct Exercise { // Name of the exercise pub name: String, diff --git a/src/main.rs b/src/main.rs index 3b7a1942..5af5febc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use crate::exercise::{Exercise, ExerciseList}; use crate::run::run; use crate::verify::verify; -use clap::{crate_version, App, Arg, SubCommand}; +use argh::FromArgs; use console::Emoji; use notify::DebouncedEvent; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; @@ -22,85 +22,91 @@ mod exercise; mod run; mod verify; -fn main() { - let matches = App::new("rustlings") - .version(crate_version!()) - .author("Marisa, Carol Nichols") - .about("Rustlings is a collection of small exercises to get you used to writing and reading Rust code") - .arg( - Arg::with_name("nocapture") - .long("nocapture") - .help("Show outputs from the test exercises") - ) - .subcommand( - SubCommand::with_name("verify") - .alias("v") - .about("Verifies all exercises according to the recommended order") - ) - .subcommand( - SubCommand::with_name("watch") - .alias("w") - .about("Reruns `verify` when files were edited") - ) - .subcommand( - SubCommand::with_name("run") - .alias("r") - .about("Runs/Tests a single exercise") - .arg(Arg::with_name("name").required(true).index(1)), - ) - .subcommand( - SubCommand::with_name("hint") - .alias("h") - .about("Returns a hint for the current exercise") - .arg(Arg::with_name("name").required(true).index(1)), - ) - .subcommand( - SubCommand::with_name("list") - .alias("l") - .about("Lists the exercises available in rustlings") - .arg( - Arg::with_name("paths") - .long("paths") - .short("p") - .conflicts_with("names") - .help("Show only the paths of the exercises") - ) - .arg( - Arg::with_name("names") - .long("names") - .short("n") - .conflicts_with("paths") - .help("Show only the names of the exercises") - ) - .arg( - Arg::with_name("filter") - .long("filter") - .short("f") - .takes_value(true) - .empty_values(false) - .help( - "Provide a string to match the exercise names.\ - \nComma separated patterns are acceptable." - ) - ) - .arg( - Arg::with_name("unsolved") - .long("unsolved") - .short("u") - .conflicts_with("solved") - .help("Display only exercises not yet solved") - ) - .arg( - Arg::with_name("solved") - .long("solved") - .short("s") - .conflicts_with("unsolved") - .help("Display only exercises that have been solved") - ) - ) - .get_matches(); +// In sync with crate version +const VERSION: &str = "4.3.0"; - if matches.subcommand_name().is_none() { +#[derive(FromArgs, PartialEq, Debug)] +/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code +struct Args { + /// show outputs from the test exercises + #[argh(switch)] + nocapture: bool, + /// show the executable version + #[argh(switch, short = 'v')] + version: bool, + #[argh(subcommand)] + nested: Option, +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand)] +enum Subcommands { + Verify(VerifyArgs), + Watch(WatchArgs), + Run(RunArgs), + Hint(HintArgs), + List(ListArgs), +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "verify")] +/// Verifies all exercises according to the recommended order +struct VerifyArgs {} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "watch")] +/// Reruns `verify` when files were edited +struct WatchArgs {} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "run")] +/// Runs/Tests a single exercise +struct RunArgs { + #[argh(positional)] + /// the name of the exercise + name: String, +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "hint")] +/// Returns a hint for the given exercise +struct HintArgs { + #[argh(positional)] + /// the name of the exercise + name: String, +} + +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "list")] +/// Lists the exercises available in Rustlings +struct ListArgs { + #[argh(switch, short = 'p')] + /// show only the paths of the exercises + paths: bool, + #[argh(switch, short = 'n')] + /// show only the names of the exercises + names: bool, + #[argh(option, short = 'f')] + /// provide a string to match exercise names + /// comma separated patterns are acceptable + filter: Option, + #[argh(switch, short = 'u')] + /// display only exercises not yet solved + unsolved: bool, + #[argh(switch, short = 's')] + /// display only exercises that have been solved + solved: bool, +} + +fn main() { + let args: Args = argh::from_env(); + + if args.version { + println!("v{}", VERSION); + std::process::exit(0); + } + + if args.nested.is_none() { println!(); println!(r#" welcome to... "#); println!(r#" _ _ _ "#); @@ -130,144 +136,129 @@ fn main() { let toml_str = &fs::read_to_string("info.toml").unwrap(); let exercises = toml::from_str::(toml_str).unwrap().exercises; - let verbose = matches.is_present("nocapture"); + let verbose = args.nocapture; - // Handle the list command - if let Some(list_m) = matches.subcommand_matches("list") { - if ["paths", "names"].iter().all(|k| !list_m.is_present(k)) { - println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status"); - } - let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase(); - let mut exercises_done: u16 = 0; - exercises.iter().for_each(|e| { - let fname = format!("{}", e.path.display()); - let filter_cond = filters - .split(',') - .filter(|f| !f.trim().is_empty()) - .any(|f| e.name.contains(&f) || fname.contains(&f)); - let status = if e.looks_done() { - exercises_done = exercises_done + 1; - "Done" - } else { - "Pending" - }; - let solve_cond = { - (e.looks_done() && list_m.is_present("solved")) - || (!e.looks_done() && list_m.is_present("unsolved")) - || (!list_m.is_present("solved") && !list_m.is_present("unsolved")) - }; - if solve_cond && (filter_cond || !list_m.is_present("filter")) { - let line = if list_m.is_present("paths") { - format!("{}\n", fname) - } else if list_m.is_present("names") { - format!("{}\n", e.name) - } else { - format!("{:<17}\t{:<46}\t{:<7}\n", e.name, fname, status) - }; - // Somehow using println! leads to the binary panicking - // when its output is piped. - // So, we're handling a Broken Pipe error and exiting with 0 anyway - let stdout = std::io::stdout(); - { - let mut handle = stdout.lock(); - handle.write_all(line.as_bytes()).unwrap_or_else(|e| { - match e.kind() { - std::io::ErrorKind::BrokenPipe => std::process::exit(0), - _ => std::process::exit(1), - }; - }); - } - } - }); - let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0; - println!( - "Progress: You completed {} / {} exercises ({:.2} %).", - exercises_done, - exercises.len(), - percentage_progress - ); - std::process::exit(0); - } - - // Handle the run command - if let Some(ref matches) = matches.subcommand_matches("run") { - let name = matches.value_of("name").unwrap(); - - let matching_exercise = |e: &&Exercise| name == e.name; - - let exercise = exercises.iter().find(matching_exercise).unwrap_or_else(|| { - println!("No exercise found for your given name!"); - std::process::exit(1) - }); - - run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); - } - - if let Some(ref matches) = matches.subcommand_matches("hint") { - let name = matches.value_of("name").unwrap(); - - let exercise = exercises - .iter() - .find(|e| name == e.name) - .unwrap_or_else(|| { - println!("No exercise found for your given name!"); - std::process::exit(1) - }); - - println!("{}", exercise.hint); - } - - // Handle the verify command - if matches.subcommand_matches("verify").is_some() { - verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); - } - - // Handle the watch command - if matches.subcommand_matches("watch").is_some() { - if let Err(e) = watch(&exercises, verbose) { - println!( - "Error: Could not watch your progress. Error message was {:?}.", - e - ); - println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); - std::process::exit(1); - } - println!( - "{emoji} All exercises completed! {emoji}", - emoji = Emoji("🎉", "★") - ); - println!(); - println!("+----------------------------------------------------+"); - println!("| You made it to the Fe-nish line! |"); - println!("+-------------------------- ------------------------+"); - println!(" \\/ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); - println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); - println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(); - println!("We hope you enjoyed learning about the various aspects of Rust!"); - println!("If you noticed any issues, please don't hesitate to report them to our repo."); - println!("You can also contribute your own exercises to help the greater community!"); - println!(); - println!("Before reporting an issue or contributing, please read our guidelines:"); - println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); - } - - if matches.subcommand_name().is_none() { + let command = args.nested.unwrap_or_else(|| { let text = fs::read_to_string("default_out.txt").unwrap(); println!("{}", text); + std::process::exit(0); + }); + match command { + Subcommands::List(subargs) => { + if !subargs.paths && !subargs.names { + println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status"); + } + let mut exercises_done: u16 = 0; + let filters = subargs.filter.clone().unwrap_or_default().to_lowercase(); + exercises.iter().for_each(|e| { + let fname = format!("{}", e.path.display()); + let filter_cond = filters + .split(',') + .filter(|f| !f.trim().is_empty()) + .any(|f| e.name.contains(&f) || fname.contains(&f)); + let status = if e.looks_done() { + exercises_done += 1; + "Done" + } else { + "Pending" + }; + let solve_cond = { + (e.looks_done() && subargs.solved) + || (!e.looks_done() && subargs.unsolved) + || (!subargs.solved && !subargs.unsolved) + }; + if solve_cond && (filter_cond || subargs.filter.is_none()) { + let line = if subargs.paths { + format!("{}\n", fname) + } else if subargs.names { + format!("{}\n", e.name) + } else { + format!("{:<17}\t{:<46}\t{:<7}\n", e.name, fname, status) + }; + // Somehow using println! leads to the binary panicking + // when its output is piped. + // So, we're handling a Broken Pipe error and exiting with 0 anyway + let stdout = std::io::stdout(); + { + let mut handle = stdout.lock(); + handle.write_all(line.as_bytes()).unwrap_or_else(|e| { + match e.kind() { + std::io::ErrorKind::BrokenPipe => std::process::exit(0), + _ => std::process::exit(1), + }; + }); + } + } + }); + let percentage_progress = exercises_done as f32 / exercises.len() as f32 * 100.0; + println!( + "Progress: You completed {} / {} exercises ({:.2} %).", + exercises_done, + exercises.len(), + percentage_progress + ); + std::process::exit(0); + } + + Subcommands::Run(subargs) => { + let exercise = find_exercise(subargs.name, exercises); + + run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); + } + + Subcommands::Hint(subargs) => { + let exercise = find_exercise(subargs.name, exercises); + + println!("{}", exercise.hint); + } + + Subcommands::Verify(_subargs) => { + verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); + } + + Subcommands::Watch(_subargs) => { + if let Err(e) = watch(&exercises, verbose) { + println!( + "Error: Could not watch your progress. Error message was {:?}.", + e + ); + println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); + std::process::exit(1); + } + println!( + "{emoji} All exercises completed! {emoji}", + emoji = Emoji("🎉", "★") + ); + println!(); + println!("+----------------------------------------------------+"); + println!("| You made it to the Fe-nish line! |"); + println!("+-------------------------- ------------------------+"); + println!(" \\/ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); + println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); + println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(); + println!("We hope you enjoyed learning about the various aspects of Rust!"); + println!( + "If you noticed any issues, please don't hesitate to report them to our repo." + ); + println!("You can also contribute your own exercises to help the greater community!"); + println!(); + println!("Before reporting an issue or contributing, please read our guidelines:"); + println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); + } } } @@ -294,6 +285,18 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { }); } +fn find_exercise(name: String, exercises: Vec) -> Exercise { + let matching_exercise = |e: &Exercise| name == e.name; + + exercises + .into_iter() + .find(matching_exercise) + .unwrap_or_else(|| { + println!("No exercise found for your given name!"); + std::process::exit(1) + }) +} + fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { /* Clears the terminal with an ANSI escape code. Works in UNIX and newer Windows terminals. */ From 6177b6e126852027b689ebab4e0796b2984f987b Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 21 Apr 2021 14:47:53 +0200 Subject: [PATCH 096/476] chore: Fix integration tests --- tests/integration_tests.rs | 67 ++++++++++++++------------------------ 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 1bd3bf7e..be9af965 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -24,7 +24,7 @@ fn fails_when_in_wrong_dir() { fn verify_all_success() { Command::cargo_bin("rustlings") .unwrap() - .arg("v") + .arg("verify") .current_dir("tests/fixture/success") .assert() .success(); @@ -34,7 +34,7 @@ fn verify_all_success() { fn verify_fails_if_some_fails() { Command::cargo_bin("rustlings") .unwrap() - .arg("v") + .arg("verify") .current_dir("tests/fixture/failure") .assert() .code(1); @@ -44,7 +44,7 @@ fn verify_fails_if_some_fails() { fn run_single_compile_success() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "compSuccess"]) + .args(&["run", "compSuccess"]) .current_dir("tests/fixture/success/") .assert() .success(); @@ -54,7 +54,7 @@ fn run_single_compile_success() { fn run_single_compile_failure() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "compFailure"]) + .args(&["run", "compFailure"]) .current_dir("tests/fixture/failure/") .assert() .code(1); @@ -64,7 +64,7 @@ fn run_single_compile_failure() { fn run_single_test_success() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "testSuccess"]) + .args(&["run", "testSuccess"]) .current_dir("tests/fixture/success/") .assert() .success(); @@ -74,7 +74,7 @@ fn run_single_test_success() { fn run_single_test_failure() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "testFailure"]) + .args(&["run", "testFailure"]) .current_dir("tests/fixture/failure/") .assert() .code(1); @@ -84,7 +84,7 @@ fn run_single_test_failure() { fn run_single_test_not_passed() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "testNotPassed.rs"]) + .args(&["run", "testNotPassed.rs"]) .current_dir("tests/fixture/failure/") .assert() .code(1); @@ -94,7 +94,7 @@ fn run_single_test_not_passed() { fn run_single_test_no_filename() { Command::cargo_bin("rustlings") .unwrap() - .arg("r") + .arg("run") .current_dir("tests/fixture/") .assert() .code(1); @@ -104,7 +104,7 @@ fn run_single_test_no_filename() { fn run_single_test_no_exercise() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "compNoExercise.rs"]) + .args(&["run", "compNoExercise.rs"]) .current_dir("tests/fixture/failure") .assert() .code(1); @@ -114,7 +114,7 @@ fn run_single_test_no_exercise() { fn get_hint_for_single_test() { Command::cargo_bin("rustlings") .unwrap() - .args(&["h", "testFailure"]) + .args(&["hint", "testFailure"]) .current_dir("tests/fixture/failure") .assert() .code(0) @@ -131,10 +131,15 @@ fn all_exercises_require_confirmation() { file.read_to_string(&mut s).unwrap(); s }; - source.matches("// I AM NOT DONE").next().unwrap_or_else(|| panic!( - "There should be an `I AM NOT DONE` annotation in {:?}", - path - )); + source + .matches("// I AM NOT DONE") + .next() + .unwrap_or_else(|| { + panic!( + "There should be an `I AM NOT DONE` annotation in {:?}", + path + ) + }); } } @@ -142,7 +147,7 @@ fn all_exercises_require_confirmation() { fn run_compile_exercise_does_not_prompt() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "pending_exercise"]) + .args(&["run", "pending_exercise"]) .current_dir("tests/fixture/state") .assert() .code(0) @@ -153,7 +158,7 @@ fn run_compile_exercise_does_not_prompt() { fn run_test_exercise_does_not_prompt() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "pending_test_exercise"]) + .args(&["run", "pending_test_exercise"]) .current_dir("tests/fixture/state") .assert() .code(0) @@ -164,7 +169,7 @@ fn run_test_exercise_does_not_prompt() { fn run_single_test_success_with_output() { Command::cargo_bin("rustlings") .unwrap() - .args(&["--nocapture", "r", "testSuccess"]) + .args(&["--nocapture", "run", "testSuccess"]) .current_dir("tests/fixture/success/") .assert() .code(0) @@ -175,7 +180,7 @@ fn run_single_test_success_with_output() { fn run_single_test_success_without_output() { Command::cargo_bin("rustlings") .unwrap() - .args(&["r", "testSuccess"]) + .args(&["run", "testSuccess"]) .current_dir("tests/fixture/success/") .assert() .code(0) @@ -192,26 +197,6 @@ fn run_rustlings_list() { .success(); } -#[test] -fn run_rustlings_list_conflicting_display_options() { - Command::cargo_bin("rustlings") - .unwrap() - .args(&["list", "--names", "--paths"]) - .current_dir("tests/fixture/success") - .assert() - .failure(); -} - -#[test] -fn run_rustlings_list_conflicting_solve_options() { - Command::cargo_bin("rustlings") - .unwrap() - .args(&["list", "--solved", "--unsolved"]) - .current_dir("tests/fixture/success") - .assert() - .failure(); -} - #[test] fn run_rustlings_list_no_pending() { Command::cargo_bin("rustlings") @@ -231,10 +216,7 @@ fn run_rustlings_list_both_done_and_pending() { .current_dir("tests/fixture/state") .assert() .success() - .stdout( - predicates::str::contains("Done") - .and(predicates::str::contains("Pending")) - ); + .stdout(predicates::str::contains("Done").and(predicates::str::contains("Pending"))); } #[test] @@ -258,4 +240,3 @@ fn run_rustlings_list_without_done() { .success() .stdout(predicates::str::contains("Done").not()); } - From 81be40448777fa338ebced3b0bfc1b32d6370313 Mon Sep 17 00:00:00 2001 From: Brandon Macer Date: Wed, 21 Apr 2021 08:50:03 -0400 Subject: [PATCH 097/476] feat(arc1): Add more details to description and hint (#710) Co-authored-by: bmacer Co-authored-by: marisa Co-authored-by: Roberto Vidal --- exercises/standard_library_types/arc1.rs | 19 +++++++++++++++++-- info.toml | 7 ++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index 4ad649f1..d167380c 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -1,7 +1,21 @@ // arc1.rs +// In this exercise, we are given a Vec of u32 called "numbers" with values ranging +// from 0 to 99 -- [ 0, 1, 2, ..., 98, 99 ] +// We would like to use this set of numbers within 8 different threads simultaneously. +// Each thread is going to get the sum of every eighth value, with an offset. +// The first thread (offset 0), will sum 0, 8, 16, ... +// The second thread (offset 1), will sum 1, 9, 17, ... +// The third thread (offset 2), will sum 2, 10, 18, ... +// ... +// The eighth thread (offset 7), will sum 7, 15, 23, ... + +// Because we are using threads, our values need to be thread-safe. Therefore, +// we are using Arc. We need to make a change in each of the two TODOs. + + // Make this code compile by filling in a value for `shared_numbers` where the -// TODO comment is and create an initial binding for `child_numbers` -// somewhere. Try not to create any copies of the `numbers` Vec! +// first TODO comment is, and create an initial binding for `child_numbers` +// where the second TODO comment is. Try not to create any copies of the `numbers` Vec! // Execute `rustlings hint arc1` for hints :) // I AM NOT DONE @@ -16,6 +30,7 @@ fn main() { let mut joinhandles = Vec::new(); for offset in 0..8 { + let child_numbers = // TODO joinhandles.push(thread::spawn(move || { let mut i = offset; let mut sum = 0; diff --git a/info.toml b/info.toml index 36dcbe90..82e11952 100644 --- a/info.toml +++ b/info.toml @@ -679,7 +679,12 @@ to avoid creating a copy of `numbers`, you'll need to create `child_numbers` inside the loop but still in the main thread. `child_numbers` should be a clone of the Arc of the numbers instead of a -thread-local copy of the numbers.""" +thread-local copy of the numbers. + +This is a simple exercise if you understand the underlying concepts, but if this +is too much of a struggle, consider reading through all of Chapter 16 in the book: +https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html +""" [[exercises]] name = "iterators1" From 293dfb35d53aba5f9566f980197f93545ed2216d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 21 Apr 2021 12:50:26 +0000 Subject: [PATCH 098/476] 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 2d2cb0ef..e76a04dc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-89-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-90-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -277,6 +277,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Shao Yang Hong

🖋 +
Brandon Macer

🖋 From 8d0490bd70c7f4227a5aa43b259359a13117435d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 21 Apr 2021 12:50:27 +0000 Subject: [PATCH 099/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index e820b426..2820d18a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -829,6 +829,15 @@ "contributions": [ "content" ] + }, + { + "login": "bmacer", + "name": "Brandon Macer", + "avatar_url": "https://avatars.githubusercontent.com/u/13931806?v=4", + "profile": "https://github.com/bmacer", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 347f30bd867343c5ace1097e085a1f7e356553f7 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 21 Apr 2021 16:21:56 +0200 Subject: [PATCH 100/476] fix(main): Let find_exercise work with borrows --- src/main.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5af5febc..a95a09d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -201,13 +201,13 @@ fn main() { } Subcommands::Run(subargs) => { - let exercise = find_exercise(subargs.name, exercises); + let exercise = find_exercise(&subargs.name, &exercises); run(&exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); } Subcommands::Hint(subargs) => { - let exercise = find_exercise(subargs.name, exercises); + let exercise = find_exercise(&subargs.name, &exercises); println!("{}", exercise.hint); } @@ -285,14 +285,12 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { }); } -fn find_exercise(name: String, exercises: Vec) -> Exercise { - let matching_exercise = |e: &Exercise| name == e.name; - +fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise { exercises - .into_iter() - .find(matching_exercise) + .iter() + .find(|e| e.name == name) .unwrap_or_else(|| { - println!("No exercise found for your given name!"); + println!("No exercise found for '{}'!", name); std::process::exit(1) }) } From 1120db57a6c20966184eb8f731804604270ff2f1 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Thu, 22 Apr 2021 21:32:29 +0200 Subject: [PATCH 101/476] docs(errors): add additional help for Result/Boxing add additional help information provided by the rust by example book --- exercises/error_handling/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exercises/error_handling/README.md b/exercises/error_handling/README.md index 77a58d18..478510a4 100644 --- a/exercises/error_handling/README.md +++ b/exercises/error_handling/README.md @@ -3,3 +3,9 @@ For this exercise check out the sections: - [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html) of the Rust Book. + +or alternatively, check out the sections: +- [Result](https://doc.rust-lang.org/rust-by-example/error/result.html) +- [Boxing errors](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html) + +of the Rust By Example Book. From f253103a314b9cdbda1d6271015cf64e5b2347bd Mon Sep 17 00:00:00 2001 From: Zerotask Date: Thu, 22 Apr 2021 22:11:04 +0200 Subject: [PATCH 102/476] docs(generics): add bounds help add help for bounds provided by the rust by example book --- exercises/generics/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/generics/README.md b/exercises/generics/README.md index 7105f06f..12170d4a 100644 --- a/exercises/generics/README.md +++ b/exercises/generics/README.md @@ -4,4 +4,5 @@ In this section you'll learn about saving yourself many lines of code with gener ### Book Sections -- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html) \ No newline at end of file +- [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html) +- [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html) From 249ad44cc03974fd34708c23d9832b1729c6e844 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Fri, 23 Apr 2021 19:54:31 +0200 Subject: [PATCH 103/476] docs(exercises): updated all exercises readme files all exercises readme files now have a unified structure and a description --- exercises/clippy/README.md | 6 ++++-- exercises/collections/README.md | 6 ++++-- exercises/conversions/README.md | 9 +++++---- exercises/enums/README.md | 4 ++-- exercises/error_handling/README.md | 14 +++++++------- exercises/functions/README.md | 4 ++-- exercises/generics/README.md | 9 ++++++--- exercises/if/README.md | 4 ++-- exercises/macros/README.md | 4 ++-- exercises/modules/README.md | 4 ++-- exercises/move_semantics/README.md | 4 ++-- exercises/option/README.md | 15 ++++++++++++--- exercises/primitive_types/README.md | 4 ++-- exercises/standard_library_types/README.md | 11 ++++++++--- exercises/strings/README.md | 4 ++-- exercises/structs/README.md | 4 ++-- exercises/tests/README.md | 4 ++-- exercises/threads/README.md | 10 +++++++++- exercises/traits/README.md | 11 +++++------ exercises/variables/README.md | 8 +++++--- 20 files changed, 85 insertions(+), 54 deletions(-) diff --git a/exercises/clippy/README.md b/exercises/clippy/README.md index 60a12fe5..55438af6 100644 --- a/exercises/clippy/README.md +++ b/exercises/clippy/README.md @@ -1,8 +1,10 @@ -### Clippy +# Clippy The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code. If you used the installation script for Rustlings, Clippy should be already installed. If not you can install it manually via `rustup component add clippy`. -For more information about Clippy lints, please see [their documentation page](https://rust-lang.github.io/rust-clippy/master/). +## Further information + +- [GitHub Repository](https://github.com/rust-lang/rust-clippy). diff --git a/exercises/collections/README.md b/exercises/collections/README.md index af87863b..0291bc87 100644 --- a/exercises/collections/README.md +++ b/exercises/collections/README.md @@ -1,4 +1,4 @@ -### Collections +# Collections Rust’s standard library includes a number of very useful data structures called collections. Most other data types represent one @@ -17,4 +17,6 @@ structures that are used very often in Rust programs: You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. -[Rust book chapter](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) +## Further information + +- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) diff --git a/exercises/conversions/README.md b/exercises/conversions/README.md index 114bd428..8d7da93e 100644 --- a/exercises/conversions/README.md +++ b/exercises/conversions/README.md @@ -1,5 +1,4 @@ -### Type conversions - +# Type conversions Rust offers a multitude of ways to convert a value of a given type into another type. @@ -15,6 +14,8 @@ Furthermore, the `std::str` module offers a trait called [`FromStr`](https://doc These should be the main ways ***within the standard library*** to convert data into your desired types. -#### Book Sections +## Further information -These are not directly covered in the book, but the standard library has great documentation for [conversions here](https://doc.rust-lang.org/std/convert/index.html). The `FromStr` trait is also covered [here](https://doc.rust-lang.org/std/str/trait.FromStr.html). \ No newline at end of file +These are not directly covered in the book, but the standard library has a great documentation for it. +- [conversions](https://doc.rust-lang.org/std/convert/index.html) +- [`FromStr` trait](https://doc.rust-lang.org/std/str/trait.FromStr.html) \ No newline at end of file diff --git a/exercises/enums/README.md b/exercises/enums/README.md index 091f5d04..30d4d91d 100644 --- a/exercises/enums/README.md +++ b/exercises/enums/README.md @@ -1,10 +1,10 @@ -### Enums +# Enums Rust allows you to define types called "enums" which enumerate possible values. Enums are a feature in many languages, but their capabilities differ in each language. Rust’s enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell. Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration. -#### Book Sections +## Further information - [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html) - [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html) diff --git a/exercises/error_handling/README.md b/exercises/error_handling/README.md index 478510a4..5255ace9 100644 --- a/exercises/error_handling/README.md +++ b/exercises/error_handling/README.md @@ -1,11 +1,11 @@ -For this exercise check out the sections: +# Error handling +Most errors aren’t serious enough to require the program to stop entirely. +Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to. +For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process. + +## Further information + - [Error Handling](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) - [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html) - -of the Rust Book. - -or alternatively, check out the sections: - [Result](https://doc.rust-lang.org/rust-by-example/error/result.html) - [Boxing errors](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html) - -of the Rust By Example Book. diff --git a/exercises/functions/README.md b/exercises/functions/README.md index 351ae023..66547bd4 100644 --- a/exercises/functions/README.md +++ b/exercises/functions/README.md @@ -1,7 +1,7 @@ -### Functions +# Functions Here, you'll learn how to write functions and how Rust's compiler can trace things way back. -#### Book Sections +## Further information - [How Functions Work](https://doc.rust-lang.org/book/ch03-03-how-functions-work.html) diff --git a/exercises/generics/README.md b/exercises/generics/README.md index 12170d4a..de46d503 100644 --- a/exercises/generics/README.md +++ b/exercises/generics/README.md @@ -1,8 +1,11 @@ -### Generics +# Generics -In this section you'll learn about saving yourself many lines of code with generics! +Generics is the topic of generalizing types and functionalities to broader cases. +This is extremely useful for reducing code duplication in many ways, but can call for rather involving syntax. +Namely, being generic requires taking great care to specify over which types a generic type is actually considered valid. +The simplest and most common use of generics is for type parameters. -### Book Sections +## Further information - [Generic Data Types](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html) - [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html) diff --git a/exercises/if/README.md b/exercises/if/README.md index b1157218..528d9886 100644 --- a/exercises/if/README.md +++ b/exercises/if/README.md @@ -1,7 +1,7 @@ -### If +# If `if`, the most basic type of control flow, is what you'll learn here. -#### Book Sections +## Further information - [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions) diff --git a/exercises/macros/README.md b/exercises/macros/README.md index b48b880a..319d8408 100644 --- a/exercises/macros/README.md +++ b/exercises/macros/README.md @@ -1,10 +1,10 @@ -### Macros +# Macros Rust's macro system is very powerful, but also kind of difficult to wrap your head around. We're not going to teach you how to write your own fully-featured macros. Instead, we'll show you how to use and create them. -#### Book Sections +## Further information - [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html) - [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html) diff --git a/exercises/modules/README.md b/exercises/modules/README.md index bb765106..6582b000 100644 --- a/exercises/modules/README.md +++ b/exercises/modules/README.md @@ -1,7 +1,7 @@ -### Modules +# Modules In this section we'll give you an introduction to Rust's module system. -#### Book Sections +## Further information - [The Module System](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html) diff --git a/exercises/move_semantics/README.md b/exercises/move_semantics/README.md index 6842af7c..54ddd8e6 100644 --- a/exercises/move_semantics/README.md +++ b/exercises/move_semantics/README.md @@ -1,8 +1,8 @@ -### Move Semantics +# Move Semantics These exercises are adapted from [pnkfelix](https://github.com/pnkfelix)'s [Rust Tutorial](https://pnkfelix.github.io/rust-examples-icfp2014/) -- Thank you Felix!!! -#### Book Sections +## Further information For this section, the book links are especially important. diff --git a/exercises/option/README.md b/exercises/option/README.md index d17b79cc..a304bb44 100644 --- a/exercises/option/README.md +++ b/exercises/option/README.md @@ -1,8 +1,17 @@ -### Option +# Option -#### Book Sections +Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. +Option types are very common in Rust code, as they have a number of uses: +- Initial values +- Return values for functions that are not defined over their entire input range (partial functions) +- Return value for otherwise reporting simple errors, where None is returned on error +- Optional struct fields +- Struct fields that can be loaned or "taken" +- Optional function arguments +- Nullable pointers +- Swapping things out of difficult situations -To learn about Option, check out these links: +## Further Information - [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions) - [Option Module Documentation](https://doc.rust-lang.org/std/option/) diff --git a/exercises/primitive_types/README.md b/exercises/primitive_types/README.md index daa70eea..cea69b02 100644 --- a/exercises/primitive_types/README.md +++ b/exercises/primitive_types/README.md @@ -1,9 +1,9 @@ -### Primitive Types +# Primitive Types Rust has a couple of basic types that are directly implemented into the compiler. In this section, we'll go through the most important ones. -#### Book Sections +## Further information - [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html) - [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html) diff --git a/exercises/standard_library_types/README.md b/exercises/standard_library_types/README.md index 8b53dd81..809d61fe 100644 --- a/exercises/standard_library_types/README.md +++ b/exercises/standard_library_types/README.md @@ -1,5 +1,10 @@ -For the Box exercise check out the chapter [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html). +# Standard library types -For the Arc exercise check out the chapter [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) of the Rust Book. +This section will teach you about Box, Shared-State Concurrency and Iterators. -For the Iterator exercise check out the chapters [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) of the Rust Book and the [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/). +## Further information + +- [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html) +- [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) +- [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) +- [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/) diff --git a/exercises/strings/README.md b/exercises/strings/README.md index 38d24c84..fa2104cc 100644 --- a/exercises/strings/README.md +++ b/exercises/strings/README.md @@ -1,9 +1,9 @@ -### Strings +# Strings Rust has two string types, a string slice (`&str`) and an owned string (`String`). We're not going to dictate when you should use which one, but we'll show you how to identify and create them, as well as use them. -#### Book Sections +## Further information - [Strings](https://doc.rust-lang.org/book/ch08-02-strings.html) diff --git a/exercises/structs/README.md b/exercises/structs/README.md index 58e5a6a4..3fc1fdc9 100644 --- a/exercises/structs/README.md +++ b/exercises/structs/README.md @@ -1,8 +1,8 @@ -### Structs +# Structs Rust has three struct types: a classic C struct, a tuple struct, and a unit struct. -#### Book Sections +## Further information - [Structures](https://doc.rust-lang.org/book/ch05-01-defining-structs.html) - [Method Syntax](https://doc.rust-lang.org/book/ch05-03-method-syntax.html) diff --git a/exercises/tests/README.md b/exercises/tests/README.md index dbb14a83..27c6818d 100644 --- a/exercises/tests/README.md +++ b/exercises/tests/README.md @@ -1,7 +1,7 @@ -### Tests +# Tests Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass! -#### Book Sections +## Further information - [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) diff --git a/exercises/threads/README.md b/exercises/threads/README.md index 2024292f..d0866947 100644 --- a/exercises/threads/README.md +++ b/exercises/threads/README.md @@ -1 +1,9 @@ -For this exercise check out the [Dining Philosophers example](https://doc.rust-lang.org/1.4.0/book/dining-philosophers.html) and the chapter [Concurrency](https://doc.rust-lang.org/book/ch16-01-threads.html) of the Rust Book. \ No newline at end of file +# Threads + +In most current operating systems, an executed program’s code is run in a process, and the operating system manages multiple processes at once. +Within your program, you can also have independent parts that run simultaneously. The features that run these independent parts are called threads. + +## Further information + +- [Dining Philosophers example](https://doc.rust-lang.org/1.4.0/book/dining-philosophers.html) +- [Using Threads to Run Code Simultaneously](https://doc.rust-lang.org/book/ch16-01-threads.html) diff --git a/exercises/traits/README.md b/exercises/traits/README.md index 8cd03ec4..de67acd0 100644 --- a/exercises/traits/README.md +++ b/exercises/traits/README.md @@ -1,4 +1,4 @@ -### Traits +# Traits A trait is a collection of methods. @@ -7,14 +7,13 @@ Data types can implement traits. To do so, the methods making up the trait are d In this way, traits are somewhat similar to Java interfaces and C++ abstract classes. Some additional common Rust traits include: - -+ `Clone` (the `clone` method), -+ `Display` (which allows formatted display via `{}`), and -+ `Debug` (which allows formatted display via `{:?}`). +- `Clone` (the `clone` method) +- `Display` (which allows formatted display via `{}`) +- `Debug` (which allows formatted display via `{:?}`) Because traits indicate shared behavior between data types, they are useful when writing generics. -#### Book Sections +## Further information - [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html) diff --git a/exercises/variables/README.md b/exercises/variables/README.md index 1e2eb596..11a7a78a 100644 --- a/exercises/variables/README.md +++ b/exercises/variables/README.md @@ -1,7 +1,9 @@ -### Variables +# Variables -Here you'll learn about simple variables. +In Rust, variables are immutable by default. +When a variable is immutable, once a value is bound to a name, you can’t change that value. +You can make them mutable by adding mut in front of the variable name. -#### Book Sections +## Further information - [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html) From eefa6562327cd537fc33b1688caf8d8512ef46de Mon Sep 17 00:00:00 2001 From: Zerotask Date: Fri, 23 Apr 2021 20:07:32 +0200 Subject: [PATCH 104/476] chore(deps): update cargo dependencies --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 367881c7..fb361569 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,9 +522,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" dependencies = [ "aho-corasick", "memchr", @@ -607,9 +607,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" [[package]] name = "smallvec" @@ -619,9 +619,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" dependencies = [ "proc-macro2", "quote", From cf42ddc4497a2577e8c8e9206523322b3a2b9fc2 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Fri, 23 Apr 2021 20:28:55 +0200 Subject: [PATCH 105/476] chore(watch): add hint for the exercises README.md rustlings watch will now show an additional hint for the corresponding README.me --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a95a09d9..bc1b71e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,7 +264,7 @@ fn main() { fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); - println!("Type 'hint' to get help or 'clear' to clear the screen"); + println!("Type 'hint' or open the corresponding README.md file to get help or type 'clear' to clear the screen."); thread::spawn(move || loop { let mut input = String::new(); match io::stdin().read_line(&mut input) { From 84461c20cbaf97a67baa55afc16989aab3e3c02d Mon Sep 17 00:00:00 2001 From: mokou Date: Sat, 24 Apr 2021 11:57:00 +0200 Subject: [PATCH 106/476] release: 4.4.0 --- CHANGELOG.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/main.rs | 2 +- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3988826e..1686bdd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,48 @@ + +## 4.4.0 (2021-04-24) + + +#### Bug Fixes + +* Fix spelling error in main.rs ([91ee27f2](https://github.com/rust-lang/rustlings/commit/91ee27f22bd3797a9db57e5fd430801c170c5db8)) +* typo in default out text ([644c49f1](https://github.com/rust-lang/rustlings/commit/644c49f1e04cbb24e95872b3a52b07d692ae3bc8)) +* **collections:** Naming exercises for vectors and hashmap ([bef39b12](https://github.com/rust-lang/rustlings/commit/bef39b125961310b34b34871e480a82e82af4678)) +* **from_str:** + * Correct typos ([5f7c89f8](https://github.com/rust-lang/rustlings/commit/5f7c89f85db1f33da01911eaa479c3a2d4721678)) + * test for error instead of unwrap/should_panic ([15e71535](https://github.com/rust-lang/rustlings/commit/15e71535f37cfaed36e22eb778728d186e2104ab)) + * use trait objects for from_str ([c3e7b831](https://github.com/rust-lang/rustlings/commit/c3e7b831786c9172ed8bd5d150f3c432f242fba9)) +* **functions3:** improve function argument type (#687) ([a6509cc4](https://github.com/rust-lang/rustlings/commit/a6509cc4d545d8825f01ddf7ee37823b372154dd)) +* **hashmap2:** Update incorrect assertion (#660) ([72aaa15e](https://github.com/rust-lang/rustlings/commit/72aaa15e6ab4b72b3422f1c6356396e20a2a2bb8)) +* **info:** Fix typo (#635) ([cddc1e86](https://github.com/rust-lang/rustlings/commit/cddc1e86e7ec744ee644cc774a4887b1a0ded3e8)) +* **iterators2:** Moved errors out of tests. ([baf4ba17](https://github.com/rust-lang/rustlings/commit/baf4ba175ba6eb92989e3dd54ecbec4bedc9a863), closes [#359](https://github.com/rust-lang/rustlings/issues/359)) +* **iterators3:** Enabled iterators3.rs to run without commented out tests. ([c6712dfc](https://github.com/rust-lang/rustlings/commit/c6712dfccd1a093e590ad22bbc4f49edc417dac0)) +* **main:** Let find_exercise work with borrows ([347f30bd](https://github.com/rust-lang/rustlings/commit/347f30bd867343c5ace1097e085a1f7e356553f7)) +* **move_semantics4:** + * Remove redundant "instead" (#640) ([cc266d7d](https://github.com/rust-lang/rustlings/commit/cc266d7d80b91e79df3f61984f231b7f1587218e)) + * Small readbility improvement (#617) ([10965920](https://github.com/rust-lang/rustlings/commit/10965920fbdf8a1efc85bed869e55a1787006404)) +* **option2:** Rename uninformative variables (#675) ([b4de6594](https://github.com/rust-lang/rustlings/commit/b4de6594380636817d13c2677ec6f472a964cf43)) +* **quiz3:** Force an answer to Q2 (#672) ([0d894e6f](https://github.com/rust-lang/rustlings/commit/0d894e6ff739943901e1ae8c904582e5c2f843bd)) +* **structs:** Add 5.3 to structs/README (#652) ([6bd791f2](https://github.com/rust-lang/rustlings/commit/6bd791f2f44aa7f0ad926df767f6b1fa8f12a9a9)) +* **structs2:** correct grammar in hint (#663) ([ebdb66c7](https://github.com/rust-lang/rustlings/commit/ebdb66c7bfb6d687a14cc511a559a222e6fc5de4)) +* **structs3:** + * reword heading comment (#664) ([9f3e8c2d](https://github.com/rust-lang/rustlings/commit/9f3e8c2dde645e5264c2d2200e68842b5f47bfa3)) + * add check to prevent naive implementation of is_international ([05a753fe](https://github.com/rust-lang/rustlings/commit/05a753fe6333d36dbee5f68c21dec04eacdc75df)) +* **threads1:** line number correction ([7857b0a6](https://github.com/rust-lang/rustlings/commit/7857b0a689b0847f48d8c14cbd1865e3b812d5ca)) +* **try_from_into:** use trait objects ([2e93a588](https://github.com/rust-lang/rustlings/commit/2e93a588e0abe8badb7eafafb9e7d073c2be5df8)) + +#### Features + +* Replace clap with argh ([7928122f](https://github.com/rust-lang/rustlings/commit/7928122fcef9ca7834d988b1ec8ca0687478beeb)) +* Replace emojis when NO_EMOJI env variable present ([8d62a996](https://github.com/rust-lang/rustlings/commit/8d62a9963708dbecd9312e8bcc4b47049c72d155)) +* Added iterators5.rs exercise. ([b29ea17e](https://github.com/rust-lang/rustlings/commit/b29ea17ea94d1862114af2cf5ced0e09c197dc35)) +* **arc1:** Add more details to description and hint (#710) ([81be4044](https://github.com/rust-lang/rustlings/commit/81be40448777fa338ebced3b0bfc1b32d6370313)) +* **cli:** Improve the list command with options, and then some ([8bbe4ff1](https://github.com/rust-lang/rustlings/commit/8bbe4ff1385c5c169c90cd3ff9253f9a91daaf8e)) +* **list:** + * updated progress percentage ([1c6f7e4b](https://github.com/rust-lang/rustlings/commit/1c6f7e4b7b9b3bd36f4da2bb2b69c549cc8bd913)) + * added progress info ([c0e3daac](https://github.com/rust-lang/rustlings/commit/c0e3daacaf6850811df5bc57fa43e0f249d5cfa4)) + + + ## 4.3.0 (2020-12-29) diff --git a/Cargo.lock b/Cargo.lock index fb361569..cc8ff94a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,7 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "rustlings" -version = "4.3.0" +version = "4.4.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 397eb996..0a757040 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.3.0" +version = "4.4.0" authors = ["Marisa ", "Carol (Nichols || Goulding) "] edition = "2018" diff --git a/README.md b/README.md index e76a04dc..cf1de15a 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Basically: Clone the repository, checkout to the latest tag, run `cargo install` ```bash git clone https://github.com/rust-lang/rustlings cd rustlings -git checkout tags/4.3.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) +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 . ``` diff --git a/src/main.rs b/src/main.rs index bc1b71e4..a80ce88e 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.3.0"; +const VERSION: &str = "4.4.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From 4a384cae4ac735e243bbc58184b1f409e914ddc5 Mon Sep 17 00:00:00 2001 From: Zerotask Date: Sat, 24 Apr 2021 12:12:49 +0200 Subject: [PATCH 107/476] docs(option): improve further information --- exercises/option/README.md | 2 ++ exercises/option/option1.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/option/README.md b/exercises/option/README.md index a304bb44..89c00289 100644 --- a/exercises/option/README.md +++ b/exercises/option/README.md @@ -16,3 +16,5 @@ Option types are very common in Rust code, as they have a number of uses: - [Option Enum Format](https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-enum-definitions) - [Option Module Documentation](https://doc.rust-lang.org/std/option/) - [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html) +- [if let](https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html) +- [while let](https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html) diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index 602ff1a9..17cf4f60 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -3,7 +3,7 @@ // I AM NOT DONE -// you can modify anything EXCEPT for this function's sig +// you can modify anything EXCEPT for this function's signature fn print_number(maybe_number: Option) { println!("printing: {}", maybe_number.unwrap()); } From c6b7ad8878d77202cd1f363a0d6b021ee48604ad Mon Sep 17 00:00:00 2001 From: Dan Stoian Date: Sat, 24 Apr 2021 18:32:13 +0300 Subject: [PATCH 108/476] updated README.md; specify need for admin rights --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf1de15a..99b9d6e0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ This will install Rustlings and give you access to the `rustlings` command. Run ## Windows -In PowerShell, set `ExecutionPolicy` to `RemoteSigned`: +In PowerShell (Run as Administrator), set `ExecutionPolicy` to `RemoteSigned`: ```ps Set-ExecutionPolicy RemoteSigned From 4f7dbbd2c31b49d0a34f28ae4d4ccf8210289754 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 24 Apr 2021 15:36:38 +0000 Subject: [PATCH 109/476] 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 99b9d6e0..8ca25bae 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-90-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-91-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -278,6 +278,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Shao Yang Hong

🖋
Brandon Macer

🖋 +
Stoian Dan

🖋 From 3a9ec4192dc7584a56999d70b533ec18a03a096c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 24 Apr 2021 15:36:39 +0000 Subject: [PATCH 110/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2820d18a..2f209713 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -838,6 +838,15 @@ "contributions": [ "content" ] + }, + { + "login": "stoiandan", + "name": "Stoian Dan", + "avatar_url": "https://avatars.githubusercontent.com/u/10388612?v=4", + "profile": "https://github.com/stoiandan", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, 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 111/476] 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 21c9f44168394e08338fd470b5f49b1fd235986f Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Sat, 24 Apr 2021 13:15:34 -0400 Subject: [PATCH 112/476] feat(intro): Add intro section. --- exercises/intro/README.md | 8 ++++++++ exercises/intro/intro1.rs | 19 +++++++++++++++++++ exercises/intro/intro2.rs | 9 +++++++++ exercises/variables/variables1.rs | 8 ++------ info.toml | 16 ++++++++++++++++ 5 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 exercises/intro/README.md create mode 100644 exercises/intro/intro1.rs create mode 100644 exercises/intro/intro2.rs diff --git a/exercises/intro/README.md b/exercises/intro/README.md new file mode 100644 index 00000000..d32e4a8b --- /dev/null +++ b/exercises/intro/README.md @@ -0,0 +1,8 @@ +# Intro + +Rust uses the `print!` and `println!` macros to print text to the console. + +## Further information + +- [Hello World](https://doc.rust-lang.org/rust-by-example/hello.html) +- [Formatted print](https://doc.rust-lang.org/rust-by-example/hello/print.html) diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs new file mode 100644 index 00000000..83a78e68 --- /dev/null +++ b/exercises/intro/intro1.rs @@ -0,0 +1,19 @@ +// intro1.rs +// About this `I AM NOT DONE` thing: +// We sometimes encourage you to keep trying things on a given exercise, even +// after you already figured it out. If you got everything working and feel +// ready for the next exercise, remove the `I AM NOT DONE` comment below. +// Execute the command `rustlings hint intro1` for a hint. + +// I AM NOT DONE + +fn main() { + println!("Hello and"); + println!(r#" welcome to... "#); + println!(r#" _ _ _ "#); + println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#); + println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#); + println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#); + println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#); + println!(r#" |___/ "#); +} diff --git a/exercises/intro/intro2.rs b/exercises/intro/intro2.rs new file mode 100644 index 00000000..97a073f0 --- /dev/null +++ b/exercises/intro/intro2.rs @@ -0,0 +1,9 @@ +// intro2.rs +// Make the code print a greeting to the world. +// Execute `rustlings hint intro2` for a hint. + +// I AM NOT DONE + +fn main() { + println!("Hello {}!"); +} diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index 4a3af73c..d1af8311 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -1,10 +1,6 @@ // variables1.rs -// Make me compile! Execute the command `rustlings hint variables1` if you want a hint :) - -// About this `I AM NOT DONE` thing: -// We sometimes encourage you to keep trying things on a given exercise, -// even after you already figured it out. If you got everything working and -// feel ready for the next exercise, remove the `I AM NOT DONE` comment below. +// Make me compile! +// Execute the command `rustlings hint variables1` if you want a hint :) // I AM NOT DONE diff --git a/info.toml b/info.toml index 82e11952..c56b19fd 100644 --- a/info.toml +++ b/info.toml @@ -1,3 +1,19 @@ +# INTRO + +[[exercises]] +name = "intro1" +path = "exercises/intro/intro1.rs" +mode = "compile" +hint = """ +Remove the I AM NOT DONE comment to move on to the next exercise.""" + +[[exercises]] +name = "intro2" +path = "exercises/intro/intro2.rs" +mode = "compile" +hint = """ +Add an argument after the format string.""" + # VARIABLES [[exercises]] From 650b1dee541d3ad789c4ac6d461045e7c592b396 Mon Sep 17 00:00:00 2001 From: Maarten Tibau Date: Sun, 25 Apr 2021 17:49:46 +0200 Subject: [PATCH 113/476] 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 9b8de65525a5576b78cf0c8e4098cdd34296338f Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Mon, 26 Apr 2021 20:28:17 -0400 Subject: [PATCH 114/476] fix(intro1): Add compiler error explanation. --- exercises/intro/intro1.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs index 83a78e68..1c4582de 100644 --- a/exercises/intro/intro1.rs +++ b/exercises/intro/intro1.rs @@ -16,4 +16,8 @@ fn main() { println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#); println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#); println!(r#" |___/ "#); + println!(); + println!("This exercise compiles successfully. The remaining exercises contain a compiler"); + println!("or logic error. The central concept behind Rustlings is to fix these errors and"); + println!("solve the exercises. Good luck!"); } 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 115/476] 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 116/476] 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 f78c48020830d7900dd8d81f355606581670446d Mon Sep 17 00:00:00 2001 From: apogeeoak <59737221+apogeeoak@users.noreply.github.com> Date: Tue, 27 Apr 2021 17:09:44 -0400 Subject: [PATCH 117/476] fix(cli): Move long text strings into constants. --- default_out.txt | 25 ------------ src/main.rs | 104 +++++++++++++++++++++++++++++------------------- 2 files changed, 64 insertions(+), 65 deletions(-) delete mode 100644 default_out.txt diff --git a/default_out.txt b/default_out.txt deleted file mode 100644 index b90d1e3a..00000000 --- a/default_out.txt +++ /dev/null @@ -1,25 +0,0 @@ -Thanks for installing Rustlings! - -Is this your first time? Don't worry, Rustlings was made for beginners! We are -going to teach you a lot of things about Rust, but before we can get -started, here's a couple of notes about how Rustlings operates: - -1. The central concept behind Rustlings is that you solve exercises. These - exercises usually have some sort of syntax error in them, which will cause - them to fail compilation or testing. Sometimes there's a logic error instead - of a syntax error. No matter what error, it's your job to find it and fix it! - You'll know when you fixed it because then, the exercise will compile and - Rustlings will be able to move on to the next exercise. -2. If you run Rustlings in watch mode (which we recommend), it'll automatically - start with the first exercise. Don't get confused by an error message popping - up as soon as you run Rustlings! This is part of the exercise that you're - supposed to solve, so open the exercise file in an editor and start your - detective work! -3. If you're stuck on an exercise, there is a helpful hint you can view by typing - 'hint' (in watch mode), or running `rustlings hint myexercise`. -4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub! - (https://github.com/rust-lang/rustlings/issues/new). We look at every issue, - and sometimes, other learners do too so you can help each other out! - -Got all that? Great! To get started, run `rustlings watch` in order to get the first -exercise. Make sure to have your editor open! diff --git a/src/main.rs b/src/main.rs index a80ce88e..64161e58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -107,15 +107,7 @@ fn main() { } if args.nested.is_none() { - println!(); - println!(r#" welcome to... "#); - println!(r#" _ _ _ "#); - println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#); - println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#); - println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#); - println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#); - println!(r#" |___/ "#); - println!(); + println!("\n{}\n", WELCOME); } if !Path::new("info.toml").exists() { @@ -139,8 +131,7 @@ fn main() { let verbose = args.nocapture; let command = args.nested.unwrap_or_else(|| { - let text = fs::read_to_string("default_out.txt").unwrap(); - println!("{}", text); + println!("{}\n", DEFAULT_OUT); std::process::exit(0); }); match command { @@ -229,35 +220,7 @@ fn main() { "{emoji} All exercises completed! {emoji}", emoji = Emoji("🎉", "★") ); - println!(); - println!("+----------------------------------------------------+"); - println!("| You made it to the Fe-nish line! |"); - println!("+-------------------------- ------------------------+"); - println!(" \\/ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); - println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); - println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(); - println!("We hope you enjoyed learning about the various aspects of Rust!"); - println!( - "If you noticed any issues, please don't hesitate to report them to our repo." - ); - println!("You can also contribute your own exercises to help the greater community!"); - println!(); - println!("Before reporting an issue or contributing, please read our guidelines:"); - println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); + println!("\n{}\n", FENISH_LINE); } } } @@ -356,3 +319,64 @@ fn rustc_exists() -> bool { .map(|status| status.success()) .unwrap_or(false) } + +const DEFAULT_OUT: &str = r#"Thanks for installing Rustlings! + +Is this your first time? Don't worry, Rustlings was made for beginners! We are +going to teach you a lot of things about Rust, but before we can get +started, here's a couple of notes about how Rustlings operates: + +1. The central concept behind Rustlings is that you solve exercises. These + exercises usually have some sort of syntax error in them, which will cause + them to fail compilation or testing. Sometimes there's a logic error instead + of a syntax error. No matter what error, it's your job to find it and fix it! + You'll know when you fixed it because then, the exercise will compile and + Rustlings will be able to move on to the next exercise. +2. If you run Rustlings in watch mode (which we recommend), it'll automatically + start with the first exercise. Don't get confused by an error message popping + up as soon as you run Rustlings! This is part of the exercise that you're + supposed to solve, so open the exercise file in an editor and start your + detective work! +3. If you're stuck on an exercise, there is a helpful hint you can view by typing + 'hint' (in watch mode), or running `rustlings hint exercise_name`. +4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub! + (https://github.com/rust-lang/rustlings/issues/new). We look at every issue, + and sometimes, other learners do too so you can help each other out! + +Got all that? Great! To get started, run `rustlings watch` in order to get the first +exercise. Make sure to have your editor open!"#; + +const FENISH_LINE: &str = r#"+----------------------------------------------------+ +| You made it to the Fe-nish line! | ++-------------------------- ------------------------+ + \\/ + ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ + ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ + ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ + ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ + ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ + ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ + ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ + ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ + ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ + ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ + ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ + ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ + ▒▒ ▒▒ ▒▒ ▒▒ + +We hope you enjoyed learning about the various aspects of Rust! +If you noticed any issues, please don't hesitate to report them to our repo. +You can also contribute your own exercises to help the greater community! + +Before reporting an issue or contributing, please read our guidelines: +https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"#; + +const WELCOME: &str = r#" welcome to... + _ _ _ + _ __ _ _ ___| |_| (_)_ __ __ _ ___ + | '__| | | / __| __| | | '_ \ / _` / __| + | | | |_| \__ \ |_| | | | | | (_| \__ \ + |_| \__,_|___/\__|_|_|_| |_|\__, |___/ + |___/"#; From 9569c9a9e72fb0ff792437207a579930cea8f9fb Mon Sep 17 00:00:00 2001 From: Pi Delport Date: Thu, 29 Apr 2021 23:31:26 +0200 Subject: [PATCH 118/476] 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 119/476] 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 120/476] 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 121/476] 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 122/476] 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 123/476] 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 124/476] 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 125/476] 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 126/476] 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 127/476] 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 128/476] 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 129/476] 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 130/476] 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 131/476] 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 132/476] 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 133/476] 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 134/476] 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 135/476] 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 136/476] 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 137/476] 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 138/476] 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 139/476] 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 2dc93caddad43821743e4903d89b355df58d7a49 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Thu, 24 Jun 2021 21:33:41 -0500 Subject: [PATCH 140/476] fix(from_str, try_from_into): custom error types Remove the use of trait objects as errors from `from_str` and `try_from_into`; they seem to have caused a lot of confusion in practice. (Also, it's considered best practice to use custom error types instead of boxed errors in library code.) Instead, use custom error enums, and update hints accordingly. Hints also provide some guidance about converting errors, which could be covered more completely in a future advanced errors section. Also move from_str to directly after the similar exercise `from_into`, for the sake of familiarity when solving. --- exercises/conversions/from_str.rs | 56 ++++++++++++++----- exercises/conversions/try_from_into.rs | 74 ++++++++++++++++++-------- info.toml | 53 ++++++++++-------- 3 files changed, 127 insertions(+), 56 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 4beebacd..6e9e699d 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -1,16 +1,31 @@ -// This does practically the same thing that TryFrom<&str> does. +// from_str.rs +// This is similar to from_into.rs, but this time we'll implement `FromStr` +// and return errors instead of falling back to a default value. // Additionally, upon implementing FromStr, you can use the `parse` method // on strings to generate an object of the implementor type. // You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html -use std::error; +use std::num::ParseIntError; use std::str::FromStr; -#[derive(Debug)] +#[derive(Debug, PartialEq)] struct Person { name: String, age: usize, } +// We will use this error type for the `FromStr` implementation. +#[derive(Debug, PartialEq)] +enum ParsePersonError { + // Empty input string + Empty, + // Incorrect number of fields + BadLen, + // Empty name field + NoName, + // Wrapped error from parse::() + ParseInt(ParseIntError), +} + // I AM NOT DONE // Steps: @@ -24,7 +39,7 @@ struct Person { // If everything goes well, then return a Result of a Person object impl FromStr for Person { - type Err = Box; + type Err = ParsePersonError; fn from_str(s: &str) -> Result { } } @@ -40,7 +55,7 @@ mod tests { #[test] fn empty_input() { - assert!("".parse::().is_err()); + assert_eq!("".parse::(), Err(ParsePersonError::Empty)); } #[test] fn good_input() { @@ -52,41 +67,56 @@ mod tests { } #[test] fn missing_age() { - assert!("John,".parse::().is_err()); + assert!(matches!( + "John,".parse::(), + Err(ParsePersonError::ParseInt(_)) + )); } #[test] fn invalid_age() { - assert!("John,twenty".parse::().is_err()); + assert!(matches!( + "John,twenty".parse::(), + Err(ParsePersonError::ParseInt(_)) + )); } #[test] fn missing_comma_and_age() { - assert!("John".parse::().is_err()); + assert_eq!("John".parse::(), Err(ParsePersonError::BadLen)); } #[test] fn missing_name() { - assert!(",1".parse::().is_err()); + assert_eq!(",1".parse::(), Err(ParsePersonError::NoName)); } #[test] fn missing_name_and_age() { - assert!(",".parse::().is_err()); + assert!(matches!( + ",".parse::(), + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)) + )); } #[test] fn missing_name_and_invalid_age() { - assert!(",one".parse::().is_err()); + assert!(matches!( + ",one".parse::(), + Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)) + )); } #[test] fn trailing_comma() { - assert!("John,32,".parse::().is_err()); + assert_eq!("John,32,".parse::(), Err(ParsePersonError::BadLen)); } #[test] fn trailing_comma_and_some_string() { - assert!("John,32,man".parse::().is_err()); + assert_eq!( + "John,32,man".parse::(), + Err(ParsePersonError::BadLen) + ); } } diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index c0b5d986..b8ec4455 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -1,9 +1,9 @@ +// try_from_into.rs // TryFrom is a simple and safe type conversion that may fail in a controlled way under some circumstances. // Basically, this is the same as From. The main difference is that this should return a Result type // instead of the target type itself. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html use std::convert::{TryFrom, TryInto}; -use std::error; #[derive(Debug, PartialEq)] struct Color { @@ -12,12 +12,21 @@ struct Color { blue: u8, } +// We will use this error type for these `TryFrom` conversions. +#[derive(Debug, PartialEq)] +enum IntoColorError { + // Incorrect length of slice + BadLen, + // Integer conversion error + IntConversion, +} + // I AM NOT DONE // Your task is to complete this implementation // and return an Ok result of inner type Color. // You need to create an implementation for a tuple of three integers, -// an array of three integers and a slice of integers. +// an array of three integers, and a slice of integers. // // Note that the implementation for tuple and array will be checked at compile time, // but the slice implementation needs to check the slice length! @@ -25,20 +34,23 @@ struct Color { // Tuple implementation impl TryFrom<(i16, i16, i16)> for Color { - type Error = Box; - fn try_from(tuple: (i16, i16, i16)) -> Result {} + type Error = IntoColorError; + fn try_from(tuple: (i16, i16, i16)) -> Result { + } } // Array implementation impl TryFrom<[i16; 3]> for Color { - type Error = Box; - fn try_from(arr: [i16; 3]) -> Result {} + type Error = IntoColorError; + fn try_from(arr: [i16; 3]) -> Result { + } } // Slice implementation impl TryFrom<&[i16]> for Color { - type Error = Box; - fn try_from(slice: &[i16]) -> Result {} + type Error = IntoColorError; + fn try_from(slice: &[i16]) -> Result { + } } fn main() { @@ -46,15 +58,15 @@ fn main() { let c1 = Color::try_from((183, 65, 14)); println!("{:?}", c1); - // Since From is implemented for Color, we should be able to use Into + // Since TryFrom is implemented for Color, we should be able to use TryInto let c2: Result = [183, 65, 14].try_into(); println!("{:?}", c2); let v = vec![183, 65, 14]; - // With slice we should use `from` function + // With slice we should use `try_from` function let c3 = Color::try_from(&v[..]); println!("{:?}", c3); - // or take slice within round brackets and use Into + // or take slice within round brackets and use TryInto let c4: Result = (&v[..]).try_into(); println!("{:?}", c4); } @@ -65,15 +77,24 @@ mod tests { #[test] fn test_tuple_out_of_range_positive() { - assert!(Color::try_from((256, 1000, 10000)).is_err()); + assert_eq!( + Color::try_from((256, 1000, 10000)), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_tuple_out_of_range_negative() { - assert!(Color::try_from((-1, -10, -256)).is_err()); + assert_eq!( + Color::try_from((-1, -10, -256)), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_tuple_sum() { - assert!(Color::try_from((-1, 255, 255)).is_err()); + assert_eq!( + Color::try_from((-1, 255, 255)), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_tuple_correct() { @@ -91,17 +112,17 @@ mod tests { #[test] fn test_array_out_of_range_positive() { let c: Result = [1000, 10000, 256].try_into(); - assert!(c.is_err()); + assert_eq!(c, Err(IntoColorError::IntConversion)); } #[test] fn test_array_out_of_range_negative() { let c: Result = [-10, -256, -1].try_into(); - assert!(c.is_err()); + assert_eq!(c, Err(IntoColorError::IntConversion)); } #[test] fn test_array_sum() { let c: Result = [-1, 255, 255].try_into(); - assert!(c.is_err()); + assert_eq!(c, Err(IntoColorError::IntConversion)); } #[test] fn test_array_correct() { @@ -119,17 +140,26 @@ mod tests { #[test] fn test_slice_out_of_range_positive() { let arr = [10000, 256, 1000]; - assert!(Color::try_from(&arr[..]).is_err()); + assert_eq!( + Color::try_from(&arr[..]), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_slice_out_of_range_negative() { let arr = [-256, -1, -10]; - assert!(Color::try_from(&arr[..]).is_err()); + assert_eq!( + Color::try_from(&arr[..]), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_slice_sum() { let arr = [-1, 255, 255]; - assert!(Color::try_from(&arr[..]).is_err()); + assert_eq!( + Color::try_from(&arr[..]), + Err(IntoColorError::IntConversion) + ); } #[test] fn test_slice_correct() { @@ -148,11 +178,11 @@ mod tests { #[test] fn test_slice_excess_length() { let v = vec![0, 0, 0, 0]; - assert!(Color::try_from(&v[..]).is_err()); + assert_eq!(Color::try_from(&v[..]), Err(IntoColorError::BadLen)); } #[test] fn test_slice_insufficient_length() { let v = vec![0, 0]; - assert!(Color::try_from(&v[..]).is_err()); + assert_eq!(Color::try_from(&v[..]), Err(IntoColorError::BadLen)); } } diff --git a/info.toml b/info.toml index ab4dc933..f5af8840 100644 --- a/info.toml +++ b/info.toml @@ -925,6 +925,27 @@ mode = "test" hint = """ Follow the steps provided right before the `From` implementation""" +[[exercises]] +name = "from_str" +path = "exercises/conversions/from_str.rs" +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 `from_into` exercise, but returning errors instead +of falling back to a default value. + +Hint: Look at the test cases to see which error variants to return. + +Another hint: You can use the `map_err` method of `Result` with a function +or a closure to wrap the error from `parse::`. + +Yet another hint: If you would like to propagate errors by using the `?` +operator in your solution, you might want to look at +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html +""" + [[exercises]] name = "try_from_into" path = "exercises/conversions/try_from_into.rs" @@ -933,17 +954,19 @@ 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 errors5 (or its hints) to remind -yourself about how `Box` works. +Hint: Is there an implementation of `TryFrom` in the standard library that +can both do the required integer conversion and check the range of the input? -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. +Another hint: Look at the test cases to see which error variants to return. -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.""" +Yet another hint: You can use the `map_err` or `or` methods of `Result` to +convert errors. + +Yet another hint: If you would like to propagate errors by using the `?` +operator in your solution, you might want to look at +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/reenter_question_mark.html + +Challenge: Can you make the `TryFrom` implementations generic over many integer types?""" [[exercises]] name = "as_ref_mut" @@ -951,15 +974,3 @@ path = "exercises/conversions/as_ref_mut.rs" mode = "test" hint = """ Add AsRef as a trait bound to the functions.""" - -[[exercises]] -name = "from_str" -path = "exercises/conversions/from_str.rs" -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. - -If you're having trouble with returning the correct error type, see the -hints for try_from_into.""" From 3a4433d5a2961e3f3e613bd67459579fbc6277fa Mon Sep 17 00:00:00 2001 From: arlecchino Date: Mon, 28 Jun 2021 17:08:53 +0200 Subject: [PATCH 141/476] 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 142/476] 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 143/476] 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 144/476] 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 145/476] 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 146/476] 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 147/476] 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 148/476] 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 149/476] 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 150/476] 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 151/476] 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 152/476] 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 153/476] 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 154/476] 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 155/476] 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 156/476] 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 157/476] 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 158/476] 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 159/476] 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 160/476] 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 161/476] 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 162/476] 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 163/476] 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 164/476] 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 165/476] 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 166/476] 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 167/476] 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 168/476] 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 169/476] 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 170/476] 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 171/476] 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 172/476] 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 173/476] 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 174/476] 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 From a7dc080b95e49146fbaafe6922a6de2f8cb1582a Mon Sep 17 00:00:00 2001 From: ana Date: Tue, 21 Sep 2021 10:36:11 +0200 Subject: [PATCH 175/476] feat: add more watch commands Includes: - quit, to quit the shell instead of having to press Cmd/Ctrl-C or Cmd/Ctrl-D - help, to display an overview of all the commands available in watch mode. Closes #842. --- src/main.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1e343478..06b41770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,7 +264,7 @@ fn main() { fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); - println!("Type 'hint' or open the corresponding README.md file to get help or type 'clear' to clear the screen."); + println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here."); thread::spawn(move || loop { let mut input = String::new(); match io::stdin().read_line(&mut input) { @@ -276,6 +276,18 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { } } else if input.eq("clear") { println!("\x1B[2J\x1B[1;1H"); + } else if input.eq("quit") { + println!("Bye!"); + std::process::exit(0); + } else if input.eq("help") { + println!("Commands available to you in watch mode:"); + println!(" hint - prints the current exercise's hint"); + println!(" clear - clears the screen"); + println!(" quit - quits watch mode"); + println!(" help - displays this help message"); + println!(""); + println!("Watch mode automatically re-evaluates the current exercise"); + println!("when you edit a file's contents.") } else { println!("unknown command: {}", input); } From 0a11bad71402b5403143d642f439f57931278c07 Mon Sep 17 00:00:00 2001 From: Weilet <32561597+Weilet@users.noreply.github.com> Date: Tue, 21 Sep 2021 16:43:44 +0800 Subject: [PATCH 176/476] feat(quiz1): add default function name in comment (#838) --- exercises/quiz1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 3af1293d..b13b9284 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -10,7 +10,7 @@ // I AM NOT DONE // Put your function here! -// fn ..... { +// fn calculate_apple_price { // Don't modify this function! #[test] From fe726f5bcafd35c56b66c9b17a962b7a5cab5ece Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 08:44:03 +0000 Subject: [PATCH 177/476] 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 e28a4815..af0cbb8f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-104-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-105-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -307,6 +307,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
anuk909

🖋 💻
granddaifuku

🖋 + +
Weilet

🖋 + From 9ddd4ca33a4cb2a6b02b03a574682c92de5d7253 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 08:44:04 +0000 Subject: [PATCH 178/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5a932d94..8811aef5 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -966,6 +966,15 @@ "contributions": [ "content" ] + }, + { + "login": "Weilet", + "name": "Weilet", + "avatar_url": "https://avatars.githubusercontent.com/u/32561597?v=4", + "profile": "https://weilet.me", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 06d5c0973a3dffa3c6c6f70acb775d4c6630323c Mon Sep 17 00:00:00 2001 From: LIU JIE Date: Tue, 21 Sep 2021 17:50:15 +0800 Subject: [PATCH 179/476] fix(cli): typo in exercise.rs (#848) --- src/exercise.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index 53457ace..ec694df9 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -133,7 +133,7 @@ path = "{}.rs""#, "Failed to write 📎 Clippy 📎 Cargo.toml file." }; fs::write(CLIPPY_CARGO_TOML_PATH, cargo_toml).expect(cargo_toml_error_msg); - // To support the ability to run the clipy exercises, build + // To support the ability to run the clippy exercises, build // an executable, in addition to running clippy. With a // compilation failure, this would silently fail. But we expect // clippy to reflect the same failure while compiling later. From 9ef63c0b9b892dd572a76db9c95947e77f82eb3c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:50:31 +0000 Subject: [PATCH 180/476] 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 af0cbb8f..94ab10f8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-105-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-106-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -309,6 +309,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Weilet

🖋 +
LIU JIE

🖋 From e9c0ca6be2a73c4dc890f2ebeaaec8aeaad06650 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:50:32 +0000 Subject: [PATCH 181/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 8811aef5..44d24396 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -975,6 +975,15 @@ "contributions": [ "content" ] + }, + { + "login": "Millione", + "name": "LIU JIE", + "avatar_url": "https://avatars.githubusercontent.com/u/38575932?v=4", + "profile": "https://github.com/Millione", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 3352b5a4d380df65763b4e64fc9e8938a3adfd80 Mon Sep 17 00:00:00 2001 From: ana Date: Fri, 24 Sep 2021 13:04:30 +0200 Subject: [PATCH 182/476] chore: improve println! usage --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 06b41770..d01a8273 100644 --- a/src/main.rs +++ b/src/main.rs @@ -285,7 +285,7 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { println!(" clear - clears the screen"); println!(" quit - quits watch mode"); println!(" help - displays this help message"); - println!(""); + println!(); println!("Watch mode automatically re-evaluates the current exercise"); println!("when you edit a file's contents.") } else { From 1caef0b43494c8b8cdd6c9260147e70d510f1aca Mon Sep 17 00:00:00 2001 From: Antoine Busch Date: Tue, 14 Sep 2021 20:34:40 +1000 Subject: [PATCH 183/476] feat: Add "quit" command to `rustlings watch` closes: #842 --- src/main.rs | 122 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 50 deletions(-) diff --git a/src/main.rs b/src/main.rs index d01a8273..30096dfe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,8 @@ use std::fs; use std::io::{self, prelude::*}; use std::path::Path; use std::process::{Command, Stdio}; -use std::sync::mpsc::channel; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::mpsc::{RecvTimeoutError, channel}; use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; @@ -217,52 +218,60 @@ fn main() { } Subcommands::Watch(_subargs) => { - if let Err(e) = watch(&exercises, verbose) { - println!( - "Error: Could not watch your progress. Error message was {:?}.", - e - ); - println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); - std::process::exit(1); + match watch(&exercises, verbose) { + Err(e) => { + println!( + "Error: Could not watch your progress. Error message was {:?}.", + e + ); + println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); + std::process::exit(1); + } + Ok(WatchStatus::Finished) => { + println!( + "{emoji} All exercises completed! {emoji}", + emoji = Emoji("🎉", "★") + ); + println!(); + println!("+----------------------------------------------------+"); + println!("| You made it to the Fe-nish line! |"); + println!("+-------------------------- ------------------------+"); + println!(" \\/ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); + println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); + println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(); + println!("We hope you enjoyed learning about the various aspects of Rust!"); + println!( + "If you noticed any issues, please don't hesitate to report them to our repo." + ); + println!("You can also contribute your own exercises to help the greater community!"); + println!(); + println!("Before reporting an issue or contributing, please read our guidelines:"); + println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); + } + Ok(WatchStatus::Unfinished) => { + println!("We hope you're enjoying learning about Rust!"); + println!("If you want to continue working on the exercises at a later point, you can simply run `rustlings watch` again"); + } } - println!( - "{emoji} All exercises completed! {emoji}", - emoji = Emoji("🎉", "★") - ); - println!(); - println!("+----------------------------------------------------+"); - println!("| You made it to the Fe-nish line! |"); - println!("+-------------------------- ------------------------+"); - println!(" \\/ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); - println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); - println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(); - println!("We hope you enjoyed learning about the various aspects of Rust!"); - println!( - "If you noticed any issues, please don't hesitate to report them to our repo." - ); - println!("You can also contribute your own exercises to help the greater community!"); - println!(); - println!("Before reporting an issue or contributing, please read our guidelines:"); - println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); } } } -fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { +fn spawn_watch_shell(failed_exercise_hint: &Arc>>, should_quit: Arc) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here."); thread::spawn(move || loop { @@ -270,15 +279,15 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { match io::stdin().read_line(&mut input) { Ok(_) => { let input = input.trim(); - if input.eq("hint") { + if input == "hint" { if let Some(hint) = &*failed_exercise_hint.lock().unwrap() { println!("{}", hint); } - } else if input.eq("clear") { + } else if input == "clear" { println!("\x1B[2J\x1B[1;1H"); } else if input.eq("quit") { + should_quit.store(true, Ordering::SeqCst); println!("Bye!"); - std::process::exit(0); } else if input.eq("help") { println!("Commands available to you in watch mode:"); println!(" hint - prints the current exercise's hint"); @@ -318,7 +327,12 @@ fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise { } } -fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { +enum WatchStatus { + Finished, + Unfinished, +} + +fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result { /* Clears the terminal with an ANSI escape code. Works in UNIX and newer Windows terminals. */ fn clear_screen() { @@ -326,6 +340,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { } let (tx, rx) = channel(); + let should_quit = Arc::new(AtomicBool::new(false)); let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?; watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?; @@ -334,12 +349,12 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { let to_owned_hint = |t: &Exercise| t.hint.to_owned(); let failed_exercise_hint = match verify(exercises.iter(), verbose) { - Ok(_) => return Ok(()), + Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))), }; - spawn_watch_shell(&failed_exercise_hint); + spawn_watch_shell(&failed_exercise_hint, Arc::clone(&should_quit)); loop { - match rx.recv() { + match rx.recv_timeout(Duration::from_secs(1)) { Ok(event) => match event { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) && b.exists() { @@ -355,7 +370,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { ); clear_screen(); match verify(pending_exercises, verbose) { - Ok(_) => return Ok(()), + Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => { let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap(); *failed_exercise_hint = Some(to_owned_hint(exercise)); @@ -365,8 +380,15 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> { } _ => {} }, + Err(RecvTimeoutError::Timeout) => { + // the timeout expired, just check the `should_quit` variable below then loop again + } Err(e) => println!("watch error: {:?}", e), } + // Check if we need to exit + if should_quit.load(Ordering::SeqCst) { + return Ok(WatchStatus::Unfinished); + } } } From c4b59aa593fc4ae952f69133068cb8f8f5ac0866 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 08:47:55 +0000 Subject: [PATCH 184/476] 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 94ab10f8..8435a107 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-106-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-107-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -310,6 +310,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Weilet

🖋
LIU JIE

🖋 +
Antoine Büsch

💻 From a1b9c50f36513ce8f8ba26dfdaec2bb427fffeb6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 08:47:56 +0000 Subject: [PATCH 185/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 44d24396..345a7ec9 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -984,6 +984,15 @@ "contributions": [ "content" ] + }, + { + "login": "abusch", + "name": "Antoine Büsch", + "avatar_url": "https://avatars.githubusercontent.com/u/506344?v=4", + "profile": "https://github.com/abusch", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From d75759e829fdcd64ef071cf4b6eae2a011a7718b Mon Sep 17 00:00:00 2001 From: frogtd <31412003+frogtd@users.noreply.github.com> Date: Sat, 25 Sep 2021 04:52:18 -0400 Subject: [PATCH 186/476] fix(move_semantics5): change &mut *y to &mut x (#814) Instead of having to explain why ```rs let mut x = 100; let y = &mut x; let mut z_owned = *y; let z = &mut z_owned; *y += 100; *z += 1000; ``` and ```rs let mut x = 100; let y = &mut x; let z = &mut *y; *y += 100; *z += 1000; ``` are different, you still get the point across about having only one mutable reference. As it stands, this exercise does too much (dereferencing and having only one mutable reference), and by doing so confuses people. Example of someone being confused by this: --- exercises/move_semantics/move_semantics5.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index 5449e951..1afe16c5 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -8,7 +8,7 @@ fn main() { let mut x = 100; let y = &mut x; - let z = &mut *y; + let z = &mut x; *y += 100; *z += 1000; assert_eq!(x, 1200); From e106d7a4f4d375fd8648cde25e4e7a1c4c6bdeac Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 08:53:04 +0000 Subject: [PATCH 187/476] 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 8435a107..ac1d84d3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-107-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-108-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -311,6 +311,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Weilet

🖋
LIU JIE

🖋
Antoine Büsch

💻 +
frogtd

🖋 From ab5ecbee7a8fab44867cd18ab030dc9de7185360 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 25 Sep 2021 08:53:05 +0000 Subject: [PATCH 188/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 345a7ec9..d18743c2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -993,6 +993,15 @@ "contributions": [ "code" ] + }, + { + "login": "frogtd", + "name": "frogtd", + "avatar_url": "https://avatars.githubusercontent.com/u/31412003?v=4", + "profile": "https://frogtd.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 882d535ba8628d5e0b37e8664b3e2f26260b2671 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Wed, 9 Jun 2021 23:26:10 -0500 Subject: [PATCH 189/476] feat: add advanced_errs1 New section and exercise to demonstrate the `From` trait for errors and its usefulness with the `?` operator. --- exercises/advanced_errors/advanced_errs1.rs | 98 +++++++++++++++++++++ info.toml | 20 +++++ 2 files changed, 118 insertions(+) create mode 100644 exercises/advanced_errors/advanced_errs1.rs diff --git a/exercises/advanced_errors/advanced_errs1.rs b/exercises/advanced_errors/advanced_errs1.rs new file mode 100644 index 00000000..4bc7b635 --- /dev/null +++ b/exercises/advanced_errors/advanced_errs1.rs @@ -0,0 +1,98 @@ +// advanced_errs1.rs + +// Remember back in errors6, we had multiple mapping functions so that we +// could translate lower-level errors into our custom error type using +// `map_err()`? What if we could use the `?` operator directly instead? + +// Make this code compile! Execute `rustlings hint advanced_errs1` for +// hints :) + +// I AM NOT DONE + +use std::num::ParseIntError; +use std::str::FromStr; + +// This is a custom error type that we will be using in the `FromStr` +// implementation. +#[derive(PartialEq, Debug)] +enum ParsePosNonzeroError { + Creation(CreationError), + ParseInt(ParseIntError), +} + +impl From for ParsePosNonzeroError { + fn from(e: CreationError) -> Self { + // TODO: complete this implementation so that the `?` operator will + // work for `CreationError` + } +} + +// TODO: implement another instance of the `From` trait here so that the +// `?` operator will work in the other place in the `FromStr` +// implementation below. + +// Don't change anything below this line. + +impl FromStr for PositiveNonzeroInteger { + type Err = ParsePosNonzeroError; + fn from_str(s: &str) -> Result { + let x: i64 = s.parse()?; + Ok(PositiveNonzeroInteger::new(x)?) + } +} + +#[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() { + // We can't construct a ParseIntError, so we have to pattern match. + assert!(matches!( + PositiveNonzeroInteger::from_str("not a number"), + Err(ParsePosNonzeroError::ParseInt(_)) + )); + } + + #[test] + fn test_negative() { + assert_eq!( + PositiveNonzeroInteger::from_str("-555"), + Err(ParsePosNonzeroError::Creation(CreationError::Negative)) + ); + } + + #[test] + fn test_zero() { + assert_eq!( + PositiveNonzeroInteger::from_str("0"), + Err(ParsePosNonzeroError::Creation(CreationError::Zero)) + ); + } + + #[test] + fn test_positive() { + let x = PositiveNonzeroInteger::new(42); + assert!(x.is_ok()); + assert_eq!(PositiveNonzeroInteger::from_str("42"), Ok(x.unwrap())); + } +} diff --git a/info.toml b/info.toml index f5af8840..8e24b7db 100644 --- a/info.toml +++ b/info.toml @@ -974,3 +974,23 @@ path = "exercises/conversions/as_ref_mut.rs" mode = "test" hint = """ Add AsRef as a trait bound to the functions.""" + +# ADVANCED ERRORS + +[[exercises]] +name = "advanced_errs1" +path = "exercises/advanced_errors/advanced_errs1.rs" +mode = "test" +hint = """ +This exercise uses an updated version of the code in errors6. The parsing +code is now in an implementation of the `FromStr` trait. Note that the +parsing code uses `?` directly, without any calls to `map_err()`. There is +one partial implementation of the `From` trait example that you should +complete. + +Details: The `?` operator calls `From::from()` on the error type to convert +it to the error type of the return type of the surrounding function. + +Hint: You will need to write another implementation of `From` that has a +different input type. +""" From abd6b70c72dc6426752ff41f09160b839e5c449e Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 25 Jun 2021 16:52:10 -0500 Subject: [PATCH 190/476] feat: add advanced_errs2 New exercise to demonstrate traits that make it easier for other code to consume our custom error types. --- exercises/advanced_errors/advanced_errs2.rs | 203 ++++++++++++++++++++ info.toml | 32 +++ 2 files changed, 235 insertions(+) create mode 100644 exercises/advanced_errors/advanced_errs2.rs diff --git a/exercises/advanced_errors/advanced_errs2.rs b/exercises/advanced_errors/advanced_errs2.rs new file mode 100644 index 00000000..d9d44d06 --- /dev/null +++ b/exercises/advanced_errors/advanced_errs2.rs @@ -0,0 +1,203 @@ +// advanced_errs2.rs + +// This exercise demonstrates a few traits that are useful for custom error +// types to implement, especially so that other code can consume the custom +// error type more usefully. + +// Make this compile, and make the tests pass! +// Execute `rustlings hint advanced_errs2` for hints. + +// Steps: +// 1. Implement a missing trait so that `main()` will compile. +// 2. Complete the partial implementation of `From` for +// `ParseClimateError`. +// 3. Handle the missing error cases in the `FromStr` implementation for +// `Climate`. +// 4. Complete the partial implementation of `Display` for +// `ParseClimateError`. + +// I AM NOT DONE + +use std::error::Error; +use std::fmt::{self, Display, Formatter}; +use std::num::{ParseFloatError, ParseIntError}; +use std::str::FromStr; + +// This is the custom error type that we will be using for the parser for +// `Climate`. +#[derive(Debug, PartialEq)] +enum ParseClimateError { + Empty, + BadLen, + NoCity, + ParseInt(ParseIntError), + ParseFloat(ParseFloatError), +} + +// This `From` implementation allows the `?` operator to work on +// `ParseIntError` values. +impl From for ParseClimateError { + fn from(e: ParseIntError) -> Self { + Self::ParseInt(e) + } +} + +// This `From` implementation allows the `?` operator to work on +// `ParseFloatError` values. +impl From for ParseClimateError { + fn from(e: ParseFloatError) -> Self { + // TODO: Complete this function + } +} + +// TODO: Implement a missing trait so that `main()` below will compile. It +// is not necessary to implement any methods inside the missing trait. + +// The `Display` trait allows for other code to obtain the error formatted +// as a user-visible string. +impl Display for ParseClimateError { + // TODO: Complete this function so that it produces the correct strings + // for each error variant. + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + // Imports the variants to make the following code more compact. + use ParseClimateError::*; + match self { + NoCity => write!(f, "no city name"), + ParseFloat(e) => write!(f, "error parsing temperature: {}", e), + _ => write!(f, "unhandled error!"), + } + } +} + +#[derive(Debug, PartialEq)] +struct Climate { + city: String, + year: u32, + temp: f32, +} + +// Parser for `Climate`. +// 1. Split the input string into 3 fields: city, year, temp. +// 2. Return an error if the string is empty or has the wrong number of +// fields. +// 3. Return an error if the city name is empty. +// 4. Parse the year as a `u32` and return an error if that fails. +// 5. Parse the temp as a `f32` and return an error if that fails. +// 6. Return an `Ok` value containing the completed `Climate` value. +impl FromStr for Climate { + type Err = ParseClimateError; + // TODO: Complete this function by making it handle the missing error + // cases. + fn from_str(s: &str) -> Result { + let v: Vec<_> = s.split(',').collect(); + let (city, year, temp) = match &v[..] { + [city, year, temp] => (city.to_string(), year, temp), + _ => return Err(ParseClimateError::BadLen), + }; + let year: u32 = year.parse()?; + let temp: f32 = temp.parse()?; + Ok(Climate { city, year, temp }) + } +} + +// Don't change anything below this line (other than to enable ignored +// tests). + +fn main() -> Result<(), Box> { + println!("{:?}", "Hong Kong,1999,25.7".parse::()?); + println!("{:?}", "".parse::()?); + Ok(()) +} + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn test_empty() { + let res = "".parse::(); + assert_eq!(res, Err(ParseClimateError::Empty)); + assert_eq!(res.unwrap_err().to_string(), "empty input"); + } + #[test] + fn test_short() { + let res = "Boston,1991".parse::(); + assert_eq!(res, Err(ParseClimateError::BadLen)); + assert_eq!(res.unwrap_err().to_string(), "incorrect number of fields"); + } + #[test] + fn test_long() { + let res = "Paris,1920,17.2,extra".parse::(); + assert_eq!(res, Err(ParseClimateError::BadLen)); + assert_eq!(res.unwrap_err().to_string(), "incorrect number of fields"); + } + #[test] + fn test_no_city() { + let res = ",1997,20.5".parse::(); + assert_eq!(res, Err(ParseClimateError::NoCity)); + assert_eq!(res.unwrap_err().to_string(), "no city name"); + } + #[test] + fn test_parse_int_neg() { + let res = "Barcelona,-25,22.3".parse::(); + assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); + let err = res.unwrap_err(); + if let ParseClimateError::ParseInt(ref inner) = err { + assert_eq!( + err.to_string(), + format!("error parsing year: {}", inner.to_string()) + ); + } else { + unreachable!(); + }; + } + #[test] + fn test_parse_int_bad() { + let res = "Beijing,foo,15.0".parse::(); + assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); + let err = res.unwrap_err(); + if let ParseClimateError::ParseInt(ref inner) = err { + assert_eq!( + err.to_string(), + format!("error parsing year: {}", inner.to_string()) + ); + } else { + unreachable!(); + }; + } + #[test] + fn test_parse_float() { + let res = "Manila,2001,bar".parse::(); + assert!(matches!(res, Err(ParseClimateError::ParseFloat(_)))); + let err = res.unwrap_err(); + if let ParseClimateError::ParseFloat(ref inner) = err { + assert_eq!( + err.to_string(), + format!("error parsing temperature: {}", inner.to_string()) + ); + } else { + unreachable!(); + }; + } + #[test] + fn test_parse_good() { + let res = "Munich,2015,23.1".parse::(); + assert_eq!( + res, + Ok(Climate { + city: "Munich".to_string(), + year: 2015, + temp: 23.1, + }) + ); + } + #[test] + #[ignore] + fn test_downcast() { + let res = "São Paulo,-21,28.5".parse::(); + assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); + let err = res.unwrap_err(); + let inner: Option<&(dyn Error + 'static)> = err.source(); + assert!(inner.is_some()); + assert!(inner.unwrap().is::()); + } +} diff --git a/info.toml b/info.toml index 8e24b7db..1b8c65d2 100644 --- a/info.toml +++ b/info.toml @@ -994,3 +994,35 @@ it to the error type of the return type of the surrounding function. Hint: You will need to write another implementation of `From` that has a different input type. """ + +[[exercises]] +name = "advanced_errs2" +path = "exercises/advanced_errors/advanced_errs2.rs" +mode = "test" +hint = """ +This exercise demonstrates a few traits that are useful for custom error +types to implement. These traits make it easier for other code to consume +the custom error type. + +Follow the steps in the comment near the top of the file. You will have to +supply a missing trait implementation, and complete a few incomplete ones. + +You may find these pages to be helpful references: +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/define_error_type.html +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html +https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/wrap_error.html + +Hint: What trait must our error type have for `main()` to return the return +type that it returns? + +Another hint: It's not necessary to implement any methods inside the missing +trait. (Some methods have default implementations that are supplied by the +trait.) + +Another hint: Consult the tests to determine which error variants (and which +error message text) to produce for certain error conditions. + +Challenge: There is one test that is marked `#[ignore]`. Can you supply the +missing code that will make it pass? You may want to consult the standard +library documentation for a certain trait for more hints. +""" From d57c1830280b2dbc1b9fe2ac3f48b51add591412 Mon Sep 17 00:00:00 2001 From: ana Date: Sat, 25 Sep 2021 11:23:05 +0200 Subject: [PATCH 191/476] release: 4.6.0 --- CHANGELOG.md | 26 ++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 +- src/main.rs | 109 ++++++++++++++++++++++++++------------------------- 5 files changed, 86 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b8cdc3..fcc39e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ + +## 4.6.0 (2021-09-25) + + +#### Features + +* add advanced_errs2 ([abd6b70c](https://github.com/rust-lang/rustlings/commit/abd6b70c72dc6426752ff41f09160b839e5c449e)) +* add advanced_errs1 ([882d535b](https://github.com/rust-lang/rustlings/commit/882d535ba8628d5e0b37e8664b3e2f26260b2671)) +* Add a farewell message when quitting `watch` ([1caef0b4](https://github.com/rust-lang/rustlings/commit/1caef0b43494c8b8cdd6c9260147e70d510f1aca)) +* add more watch commands ([a7dc080b](https://github.com/rust-lang/rustlings/commit/a7dc080b95e49146fbaafe6922a6de2f8cb1582a), closes [#842](https://github.com/rust-lang/rustlings/issues/842)) +* **modules:** update exercises, add modules3 (#822) ([dfd2fab4](https://github.com/rust-lang/rustlings/commit/dfd2fab4f33d1bf59e2e5ee03123c0c9a67a9481)) +* **quiz1:** add default function name in comment (#838) ([0a11bad7](https://github.com/rust-lang/rustlings/commit/0a11bad71402b5403143d642f439f57931278c07)) + +#### Bug Fixes + +* Correct small typo in exercises/conversions/from_str.rs ([86cc8529](https://github.com/rust-lang/rustlings/commit/86cc85295ae36948963ae52882e285d7e3e29323)) +* **cli:** typo in exercise.rs (#848) ([06d5c097](https://github.com/rust-lang/rustlings/commit/06d5c0973a3dffa3c6c6f70acb775d4c6630323c)) +* **from_str, try_from_into:** custom error types ([2dc93cad](https://github.com/rust-lang/rustlings/commit/2dc93caddad43821743e4903d89b355df58d7a49)) +* **modules2:** fix typo (#835) ([1c3beb0a](https://github.com/rust-lang/rustlings/commit/1c3beb0a59178c950dc05fe8ee2346b017429ae0)) +* **move_semantics5:** + * change &mut *y to &mut x (#814) ([d75759e8](https://github.com/rust-lang/rustlings/commit/d75759e829fdcd64ef071cf4b6eae2a011a7718b)) + * Clarify instructions ([df25684c](https://github.com/rust-lang/rustlings/commit/df25684cb79f8413915e00b5efef29369849cef1)) +* **quiz1:** Fix inconsistent wording (#826) ([03131a3d](https://github.com/rust-lang/rustlings/commit/03131a3d35d9842598150f9da817f7cc26e2669a)) + + + ## 4.5.0 (2021-07-07) diff --git a/Cargo.lock b/Cargo.lock index 57b211be..e536d1b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.5.0" +version = "4.6.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 615a09c3..3b2a85a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.5.0" +version = "4.6.0" authors = ["anastasie ", "Carol (Nichols || Goulding) "] edition = "2018" diff --git a/README.md b/README.md index ac1d84d3..18e0b73a 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.5.0) -git clone -b 4.5.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.6.0) +git clone -b 4.6.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 30096dfe..32e7bba2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use std::io::{self, prelude::*}; use std::path::Path; use std::process::{Command, Stdio}; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc::{RecvTimeoutError, channel}; +use std::sync::mpsc::{channel, RecvTimeoutError}; use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; @@ -24,7 +24,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.5.0"; +const VERSION: &str = "4.6.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code @@ -217,61 +217,64 @@ fn main() { verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); } - Subcommands::Watch(_subargs) => { - match watch(&exercises, verbose) { - Err(e) => { - println!( - "Error: Could not watch your progress. Error message was {:?}.", - e - ); - println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); - std::process::exit(1); - } - Ok(WatchStatus::Finished) => { - println!( - "{emoji} All exercises completed! {emoji}", - emoji = Emoji("🎉", "★") - ); - println!(); - println!("+----------------------------------------------------+"); - println!("| You made it to the Fe-nish line! |"); - println!("+-------------------------- ------------------------+"); - println!(" \\/ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); - println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); - println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); - println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); - println!(); - println!("We hope you enjoyed learning about the various aspects of Rust!"); - println!( - "If you noticed any issues, please don't hesitate to report them to our repo." - ); - println!("You can also contribute your own exercises to help the greater community!"); - println!(); - println!("Before reporting an issue or contributing, please read our guidelines:"); - println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); - } - Ok(WatchStatus::Unfinished) => { - println!("We hope you're enjoying learning about Rust!"); - println!("If you want to continue working on the exercises at a later point, you can simply run `rustlings watch` again"); - } + Subcommands::Watch(_subargs) => match watch(&exercises, verbose) { + Err(e) => { + println!( + "Error: Could not watch your progress. Error message was {:?}.", + e + ); + println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); + std::process::exit(1); } - } + Ok(WatchStatus::Finished) => { + println!( + "{emoji} All exercises completed! {emoji}", + emoji = Emoji("🎉", "★") + ); + println!(); + println!("+----------------------------------------------------+"); + println!("| You made it to the Fe-nish line! |"); + println!("+-------------------------- ------------------------+"); + println!(" \\/ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ "); + println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ "); + println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ "); + println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(" ▒▒ ▒▒ ▒▒ ▒▒ "); + println!(); + println!("We hope you enjoyed learning about the various aspects of Rust!"); + println!( + "If you noticed any issues, please don't hesitate to report them to our repo." + ); + println!( + "You can also contribute your own exercises to help the greater community!" + ); + println!(); + println!("Before reporting an issue or contributing, please read our guidelines:"); + println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"); + } + Ok(WatchStatus::Unfinished) => { + println!("We hope you're enjoying learning about Rust!"); + println!("If you want to continue working on the exercises at a later point, you can simply run `rustlings watch` again"); + } + }, } } -fn spawn_watch_shell(failed_exercise_hint: &Arc>>, should_quit: Arc) { +fn spawn_watch_shell( + failed_exercise_hint: &Arc>>, + should_quit: Arc, +) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here."); thread::spawn(move || loop { From bf33829da240375d086f96267fc2e02fa6b07001 Mon Sep 17 00:00:00 2001 From: Zhenghao Lu <54395432+EmisonLu@users.noreply.github.com> Date: Mon, 27 Sep 2021 16:03:28 +0800 Subject: [PATCH 192/476] fix(structs3): remove redundant 'return' (#852) --- exercises/structs/structs3.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index a80d0625..b3aa2825 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -18,11 +18,11 @@ impl Package { if weight_in_grams <= 0 { // Something goes here... } else { - return Package { + Package { sender_country, recipient_country, weight_in_grams, - }; + } } } From fed4fe78bbc0f4a9dbace1a556811a9f506237b6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 08:03:46 +0000 Subject: [PATCH 193/476] 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 18e0b73a..1c3709cc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-108-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-109-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -312,6 +312,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
LIU JIE

🖋
Antoine Büsch

💻
frogtd

🖋 +
Zhenghao Lu

🖋 From e3cfaa246dbef9ebea5ca020bdbaf018194b4974 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 27 Sep 2021 08:03:47 +0000 Subject: [PATCH 194/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d18743c2..21089c52 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1002,6 +1002,15 @@ "contributions": [ "content" ] + }, + { + "login": "EmisonLu", + "name": "Zhenghao Lu", + "avatar_url": "https://avatars.githubusercontent.com/u/54395432?v=4", + "profile": "https://github.com/EmisonLu", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 46c28d5cef3d8446b5a356b19d8dbc725f91a3a0 Mon Sep 17 00:00:00 2001 From: Fredrik Enestad Date: Thu, 30 Sep 2021 10:18:36 +0200 Subject: [PATCH 195/476] fix(move_semantics5): correct typo (#857) --- exercises/move_semantics/move_semantics5.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index 1afe16c5..c4704f9e 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -1,5 +1,5 @@ // move_semantics5.rs -// Make me compile only be reordering the lines in `main()`, but without +// Make me compile only by reordering the lines in `main()`, but without // adding, changing or removing any of them. // Execute `rustlings hint move_semantics5` for hints :) From 574bbffe0b11b5426970e4710a2275776690e85e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 08:18:52 +0000 Subject: [PATCH 196/476] 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 1c3709cc..6e5ce3f6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-109-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-110-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -313,6 +313,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Antoine Büsch

💻
frogtd

🖋
Zhenghao Lu

🖋 +
Fredrik Enestad

🖋 From ae54c17b6a5ca63705192011d11d371bb51eee97 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 08:18:53 +0000 Subject: [PATCH 197/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 21089c52..fe18385f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1011,6 +1011,15 @@ "contributions": [ "content" ] + }, + { + "login": "fredr", + "name": "Fredrik Enestad", + "avatar_url": "https://avatars.githubusercontent.com/u/762956?v=4", + "profile": "https://soundtrackyourbrand.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 1c0fe3cbcca85f90b3985985b8e265ee872a2ab2 Mon Sep 17 00:00:00 2001 From: rlch Date: Sat, 2 Oct 2021 23:59:23 +1000 Subject: [PATCH 198/476] fix: few spelling mistakes --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 21406630..5eece6d7 100644 --- a/info.toml +++ b/info.toml @@ -364,7 +364,7 @@ mode = "compile" hint = """ 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 +associated constants). Complete the `use` statements to fit the uses in main and find the one keyword missing for both constants.""" [[exercises]] From 1663a16eade6ca646b6ed061735f7982434d530d Mon Sep 17 00:00:00 2001 From: xuesong Date: Mon, 18 Oct 2021 19:57:12 +0800 Subject: [PATCH 199/476] fix(traits1): rename test functions to snake case (#854) Co-authored-by: zhangshaozhi --- exercises/advanced_errors/advanced_errs2.rs | 1 - exercises/traits/traits1.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/exercises/advanced_errors/advanced_errs2.rs b/exercises/advanced_errors/advanced_errs2.rs index d9d44d06..54e669fd 100644 --- a/exercises/advanced_errors/advanced_errs2.rs +++ b/exercises/advanced_errors/advanced_errs2.rs @@ -64,7 +64,6 @@ impl Display for ParseClimateError { match self { NoCity => write!(f, "no city name"), ParseFloat(e) => write!(f, "error parsing temperature: {}", e), - _ => write!(f, "unhandled error!"), } } } diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 2ef9e11b..15e08f24 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -29,12 +29,12 @@ mod tests { use super::*; #[test] - fn is_FooBar() { + fn is_foo_bar() { assert_eq!(String::from("Foo").append_bar(), String::from("FooBar")); } #[test] - fn is_BarBar() { + fn is_bar_bar() { assert_eq!( String::from("").append_bar().append_bar(), String::from("BarBar") From b24b295d88d0f5598c5b0fe0ff926d29ab3c5828 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:57:33 +0000 Subject: [PATCH 200/476] 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 6e5ce3f6..a3ef758d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-110-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-111-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -314,6 +314,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
frogtd

🖋
Zhenghao Lu

🖋
Fredrik Enestad

🖋 +
xuesong

🖋 From 71da9068e71ee395a30083dfc516e7dc110a2a8f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 18 Oct 2021 11:57:34 +0000 Subject: [PATCH 201/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index fe18385f..d7c7d465 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1020,6 +1020,15 @@ "contributions": [ "content" ] + }, + { + "login": "xuesongbj", + "name": "xuesong", + "avatar_url": "https://avatars.githubusercontent.com/u/18476085?v=4", + "profile": "http://xuesong.pydevops.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 359f81dd0bf5cc82016c56d374b38bf4de8f5893 Mon Sep 17 00:00:00 2001 From: ana Date: Fri, 29 Oct 2021 14:27:36 +0200 Subject: [PATCH 202/476] chore: upgrade edition to 2021 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3b2a85a7..30032695 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rustlings" version = "4.6.0" authors = ["anastasie ", "Carol (Nichols || Goulding) "] -edition = "2018" +edition = "2021" [dependencies] argh = "0.1.4" From d1ee2daf14f19105e6db3f9c610f44293d688532 Mon Sep 17 00:00:00 2001 From: Michael Walsh <48160144+MpdWalsh@users.noreply.github.com> Date: Sat, 30 Oct 2021 16:55:58 -0600 Subject: [PATCH 203/476] fix(structs3.rs): assigned value to cents_per_gram in test Intended to simplify the lesson by removing the need to figure out what the value is meant to be based on the tests. Previous commits (https://github.com/rust-lang/rustlings/commit/9ca08b8f2b09366e97896a4a8cf9ff3bb4d54380 and https://github.com/rust-lang/rustlings/commit/114b54cbdb977234b39e5f180d937c14c78bb8b2#diff-ce1c232ff0ddaff909351bb84cb5bff423b5b9e04f21fd4db7ffe443e598e174) removed the mathematical complexity, and I feel this addition is a needed change to further streamline the exercise. --- 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 b3aa2825..1a81531c 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -73,7 +73,7 @@ mod tests { let sender_country = String::from("Spain"); let recipient_country = String::from("Spain"); - let cents_per_gram = ???; + let cents_per_gram = 3; let package = Package::new(sender_country, recipient_country, 1500); From e08b6cf3ef157dd7dc65b920b36723a4c480179c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 31 Oct 2021 16:25:35 +0000 Subject: [PATCH 204/476] 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 a3ef758d..c0ba6ce9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-111-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-112-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -315,6 +315,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Zhenghao Lu

🖋
Fredrik Enestad

🖋
xuesong

🖋 +
Michael Walsh

💻 From cb661896a21aa00d46b894cdc4a7632f7569479c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 31 Oct 2021 16:25:36 +0000 Subject: [PATCH 205/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d7c7d465..cda03778 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1029,6 +1029,15 @@ "contributions": [ "content" ] + }, + { + "login": "MpdWalsh", + "name": "Michael Walsh", + "avatar_url": "https://avatars.githubusercontent.com/u/48160144?v=4", + "profile": "https://github.com/MpdWalsh", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 8ef4869b264094e5a9b50452b4534823a9df19c3 Mon Sep 17 00:00:00 2001 From: alirezaghey Date: Wed, 15 Dec 2021 10:44:21 +0100 Subject: [PATCH 206/476] fix(functions5): Remove wrong new line and small English improvements (#885) --- info.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/info.toml b/info.toml index 5eece6d7..95850c63 100644 --- a/info.toml +++ b/info.toml @@ -114,8 +114,7 @@ path = "exercises/functions/functions5.rs" mode = "compile" hint = """ This is a really common error that can be fixed by removing one character. -It happens because Rust distinguishes between expressions and statements: expressions return -a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language. +It happens because Rust distinguishes between expressions and statements: expressions return a value based on their operand(s), and statements simply return a () type which behaves just like `void` in C/C++ language. We want to return a value of `i32` type from the `square` function, but it is returning a `()` type... They are not the same. There are two solutions: 1. Add a `return` ahead of `num * num;` From 72b2c9f54f5f4d246616af767a1a842223702a13 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 15 Dec 2021 09:44:38 +0000 Subject: [PATCH 207/476] 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 c0ba6ce9..7595a9eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-112-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-113-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -317,6 +317,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
xuesong

🖋
Michael Walsh

💻 + +
alirezaghey

🖋 + From 527a5b1182483aa467556c1a36d9322440befa43 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 15 Dec 2021 09:44:39 +0000 Subject: [PATCH 208/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index cda03778..6bf3853e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1038,6 +1038,15 @@ "contributions": [ "code" ] + }, + { + "login": "alirezaghey", + "name": "alirezaghey", + "avatar_url": "https://avatars.githubusercontent.com/u/26653424?v=4", + "profile": "https://github.com/alirezaghey", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From f2650de369810867d2763e935ac0963c32ec420e Mon Sep 17 00:00:00 2001 From: Franklin van Nes Date: Wed, 15 Dec 2021 11:46:27 -0500 Subject: [PATCH 209/476] fix(clippy1): Updated code to test correctness clippy lint with approx_constant lint rule closes #888 --- exercises/clippy/clippy1.rs | 16 +++++++++++----- info.toml | 16 ++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index bdb5dd2c..c5f84a9c 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -8,10 +8,16 @@ // I AM NOT DONE +use std::f32; + fn main() { - let x = 1.2331f64; - let y = 1.2332f64; - if y != x { - println!("Success!"); - } + let pi = 3.14f32; + let radius = 5.00f32; + + let area = pi * f32::powi(radius, 2); + + println!( + "The area of a circle with radius {:.2} is {:.5}!", + radius, area + ) } diff --git a/info.toml b/info.toml index 95850c63..0c03def3 100644 --- a/info.toml +++ b/info.toml @@ -906,15 +906,15 @@ name = "clippy1" path = "exercises/clippy/clippy1.rs" mode = "clippy" hint = """ -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. +Rust stores the highest precision version of any long or inifinite precision +mathematical constants in the rust standard library. +https://doc.rust-lang.org/stable/std/f32/consts/index.html + +We may be tempted to use our own approximations for certain mathematical constants, +but clippy recognizes those imprecise mathematical constants as a source of +potential error. 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""" +appropriate replacement constant from std::f32::consts...""" [[exercises]] name = "clippy2" From 8d675198d81eedb02ef3124321670000f0f6fd6c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 13:11:14 +0000 Subject: [PATCH 210/476] 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 7595a9eb..469e1ef0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-113-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-114-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -319,6 +319,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
alirezaghey

🖋 +
Franklin van Nes

💻 From 81fb3967805a939f1149f0451afd94d566ab4d2a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 16 Dec 2021 13:11:15 +0000 Subject: [PATCH 211/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6bf3853e..f04a0ce2 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1047,6 +1047,15 @@ "contributions": [ "content" ] + }, + { + "login": "frvannes16", + "name": "Franklin van Nes", + "avatar_url": "https://avatars.githubusercontent.com/u/3188475?v=4", + "profile": "https://github.com/frvannes16", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 9b27e8d993ca20232fe38a412750c3f845a83b65 Mon Sep 17 00:00:00 2001 From: Galih wisnuaji Date: Fri, 24 Dec 2021 13:48:43 +0700 Subject: [PATCH 212/476] chore : replace filter_map() with find_map() --- src/exercise.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index ec694df9..e4a4145d 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -217,8 +217,7 @@ path = "{}.rs""#, let matched_line_index = source .lines() .enumerate() - .filter_map(|(i, line)| if re.is_match(line) { Some(i) } else { None }) - .next() + .find_map(|(i, line)| if re.is_match(line) { Some(i) } else { None }) .expect("This should not happen at all"); let min_line = ((matched_line_index as i32) - (CONTEXT as i32)).max(0) as usize; From f61f9f379638c0142f759ece850c768807a8abfd Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 12:28:07 +0000 Subject: [PATCH 213/476] 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 469e1ef0..1a878ef4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-114-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-115-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -320,6 +320,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
alirezaghey

🖋
Franklin van Nes

💻 +
nekonako

💻 From 7dce8c8b612a68ccfc1165358e075c4837b0bf92 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 12:28:08 +0000 Subject: [PATCH 214/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index f04a0ce2..6c3319ca 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1056,6 +1056,15 @@ "contributions": [ "code" ] + }, + { + "login": "nekonako", + "name": "nekonako", + "avatar_url": "https://avatars.githubusercontent.com/u/46141275?v=4", + "profile": "https://nekonako.github.io", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 1622e8c198d89739765c915203efff0091bdeb78 Mon Sep 17 00:00:00 2001 From: ZX <67887489+tan-zx@users.noreply.github.com> Date: Wed, 29 Dec 2021 14:55:37 +0800 Subject: [PATCH 215/476] fix(quiz1): update to say quiz covers "If" --- exercises/quiz1.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index b13b9284..7bd3f589 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -2,6 +2,7 @@ // This is a quiz for the following sections: // - Variables // - Functions +// - If // 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 From af84359bdb49282dbd26a72cb67d25a3823290db Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Dec 2021 11:59:05 +0000 Subject: [PATCH 216/476] 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 1a878ef4..6fe96b57 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-115-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-116-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -321,6 +321,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
alirezaghey

🖋
Franklin van Nes

💻
nekonako

💻 +
ZX

🖋 From 17e3e75331ea508efddd9a7d507bf76a16fd9a24 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 30 Dec 2021 11:59:06 +0000 Subject: [PATCH 217/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6c3319ca..91b2a486 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1065,6 +1065,15 @@ "contributions": [ "code" ] + }, + { + "login": "tan-zx", + "name": "ZX", + "avatar_url": "https://avatars.githubusercontent.com/u/67887489?v=4", + "profile": "https://github.com/tan-zx", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 71a06044e6a96ff756dc31d7b0ed665ae4badb57 Mon Sep 17 00:00:00 2001 From: radicale Date: Fri, 4 Feb 2022 14:39:09 +0100 Subject: [PATCH 218/476] fix(clippy1): Set clippy::float_cmp lint to deny (#907) --- src/exercise.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index e4a4145d..6e49a9aa 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -154,7 +154,7 @@ path = "{}.rs""#, Command::new("cargo") .args(&["clippy", "--manifest-path", CLIPPY_CARGO_TOML_PATH]) .args(RUSTC_COLOR_ARGS) - .args(&["--", "-D", "warnings"]) + .args(&["--", "-D", "warnings","-D","clippy::float_cmp"]) .output() } } From cbcde345409c3e550112e449242848eaa3391bb6 Mon Sep 17 00:00:00 2001 From: zydxhs Date: Fri, 4 Feb 2022 22:00:24 +0800 Subject: [PATCH 219/476] fix(errors1): Add a comment to make the purpose more clear (#486) Signed-off-by: zydxhs --- exercises/error_handling/errors1.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 9c24d85d..5844a497 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -36,6 +36,7 @@ mod tests { fn explains_why_generating_nametag_text_fails() { assert_eq!( generate_nametag_text("".into()), + // Don't change this line Err("`name` was empty; it must be nonempty.".into()) ); } From 4f7ff5d9c7b2d8b045194c1a9469d37e30257c4a Mon Sep 17 00:00:00 2001 From: Yang Wen Date: Fri, 4 Feb 2022 22:12:02 +0800 Subject: [PATCH 220/476] fix(structs3): Add a hint for panic (#608) as a totally newbie to Rust, I don't know panic statement from https://doc.rust-lang.org/book/ and rustlings in the beginning. After a hard searching of [should_panic], then I figure out panic statement. So it's helpful to tell the learner that write a panic statement here. --- 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 1a81531c..e84f2ebc 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -16,7 +16,7 @@ struct Package { impl Package { fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package { if weight_in_grams <= 0 { - // Something goes here... + // panic statement goes here... } else { Package { sender_country, From 52c7f8a85901b6714c732d2107823750de0d452f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 4 Feb 2022 14:13:31 +0000 Subject: [PATCH 221/476] 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 6fe96b57..b4f6a7ee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-116-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-117-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -322,6 +322,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Franklin van Nes

💻
nekonako

💻
ZX

🖋 +
Yang Wen

🖋 From a2e74a2a4bebdd48e9c4336c08c02222e36e2e6d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 4 Feb 2022 14:13:32 +0000 Subject: [PATCH 222/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 91b2a486..3f246446 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1074,6 +1074,15 @@ "contributions": [ "content" ] + }, + { + "login": "sundevilyang", + "name": "Yang Wen", + "avatar_url": "https://avatars.githubusercontent.com/u/1499214?v=4", + "profile": "https://github.com/sundevilyang", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From bc5686174463ad6f4f6b824b0e9b97c3039d4886 Mon Sep 17 00:00:00 2001 From: Brandon High Date: Fri, 4 Feb 2022 06:38:55 -0800 Subject: [PATCH 223/476] doc: Add hints on how to get gcc installed (#741) --- README.md | 1 + install.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/README.md b/README.md index b4f6a7ee..835200e8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Alternatively, for a first-time Rust learner, there are several other resources: ## Getting Started _Note: If you're on MacOS, make sure you've installed Xcode and its developer tools by typing `xcode-select --install`._ +_Note: If you're on Linux, make sure you've installed gcc. Deb: `sudo apt install gcc`. Yum: `sudo yum -y install gcc`._ You will need to have Rust installed. You can get it by visiting https://rustup.rs. This'll also install Cargo, Rust's package/project manager. diff --git a/install.sh b/install.sh index e986e741..68b8da3a 100755 --- a/install.sh +++ b/install.sh @@ -12,6 +12,18 @@ else exit 1 fi +if [ -x "$(command -v cc)" ] +then + echo "SUCCESS: cc is installed" +else + echo "ERROR: cc does not seem to be installed." + echo "Please download (g)cc using your package manager." + echo "OSX: xcode-select --install" + echo "Deb: sudo apt install gcc" + echo "Yum: sudo yum -y install gcc" + exit 1 +fi + if [ -x "$(command -v rustc)" ] then echo "SUCCESS: Rust is installed" From e96112ab998f6b121b2ea7ddf27d9e99e37dba0f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 4 Feb 2022 14:39:42 +0000 Subject: [PATCH 224/476] 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 835200e8..c9bb8b87 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-117-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-118-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -324,6 +324,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
nekonako

💻
ZX

🖋
Yang Wen

🖋 +
Brandon High

📖 From dc36ca6d84e66e1304f662770d560b3fcde7c35d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 4 Feb 2022 14:39:43 +0000 Subject: [PATCH 225/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3f246446..8207a035 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1083,6 +1083,15 @@ "contributions": [ "content" ] + }, + { + "login": "highb", + "name": "Brandon High", + "avatar_url": "https://avatars.githubusercontent.com/u/759848?v=4", + "profile": "https://brandon-high.com", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From 9be012dda0617e868c044a22e815933bc0db2cb0 Mon Sep 17 00:00:00 2001 From: Ryan Lowe Date: Sat, 5 Feb 2022 16:54:11 -0500 Subject: [PATCH 226/476] feat!: Add progress indicator closes #360 BREAKING CHANGE: verify() has a new function signature so it can know the current completion progress --- src/main.rs | 13 ++++++------- src/verify.rs | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 32e7bba2..96378ece 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,7 +214,7 @@ fn main() { } Subcommands::Verify(_subargs) => { - verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1)); + verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1)); } Subcommands::Watch(_subargs) => match watch(&exercises, verbose) { @@ -351,7 +351,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result { clear_screen(); let to_owned_hint = |t: &Exercise| t.hint.to_owned(); - let failed_exercise_hint = match verify(exercises.iter(), verbose) { + let failed_exercise_hint = match verify(exercises.iter(), (0, exercises.len()), verbose) { Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))), }; @@ -362,17 +362,16 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result { DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => { if b.extension() == Some(OsStr::new("rs")) && b.exists() { let filepath = b.as_path().canonicalize().unwrap(); - let pending_exercises = exercises - .iter() - .skip_while(|e| !filepath.ends_with(&e.path)) - // .filter(|e| filepath.ends_with(&e.path)) + let pending_exercises = exercises.iter() + .find(|e| filepath.ends_with(&e.path)).into_iter() .chain( exercises .iter() .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)), ); + let num_done = exercises.iter().filter(|e| e.looks_done()).count(); clear_screen(); - match verify(pending_exercises, verbose) { + match verify(pending_exercises, (num_done, exercises.len()), verbose) { Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => { let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap(); diff --git a/src/verify.rs b/src/verify.rs index fd59fa51..eb7af69f 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,6 +1,6 @@ use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; -use indicatif::ProgressBar; +use indicatif::{ProgressBar, ProgressStyle}; use std::env; // Verify that the provided container of Exercise objects @@ -9,10 +9,18 @@ use std::env; // If the Exercise being verified is a test, the verbose boolean // determines whether or not the test harness outputs are displayed. pub fn verify<'a>( - start_at: impl IntoIterator, + exercises: impl IntoIterator, + progress: (usize, usize), verbose: bool, ) -> Result<(), &'a Exercise> { - for exercise in start_at { + let (num_done, total) = progress; + let bar = ProgressBar::new(total as u64); + bar.set_style(ProgressStyle::default_bar() + .template("Progress: [{bar:60.green/red}] {pos}/{len}") + .progress_chars("#>-") + ); + bar.set_position(num_done as u64); + for exercise in exercises { let compile_result = match exercise.mode { Mode::Test => compile_and_test(exercise, RunMode::Interactive, verbose), Mode::Compile => compile_and_run_interactively(exercise), @@ -21,6 +29,7 @@ pub fn verify<'a>( if !compile_result.unwrap_or(false) { return Err(exercise); } + bar.inc(1); } Ok(()) } @@ -45,7 +54,6 @@ fn compile_only(exercise: &Exercise) -> Result { let _ = compile(exercise, &progress_bar)?; progress_bar.finish_and_clear(); - success!("Successfully compiled {}!", exercise); Ok(prompt_for_completion(exercise, None)) } @@ -71,8 +79,6 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { } }; - success!("Successfully ran {}!", exercise); - Ok(prompt_for_completion(exercise, Some(output.stdout))) } @@ -92,7 +98,6 @@ fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Re if verbose { println!("{}", output.stdout); } - success!("Successfully tested {}", &exercise); if let RunMode::Interactive = run_mode { Ok(prompt_for_completion(exercise, None)) } else { @@ -138,6 +143,12 @@ fn prompt_for_completion(exercise: &Exercise, prompt_output: Option) -> State::Pending(context) => context, }; + match exercise.mode { + Mode::Compile => success!("Successfully ran {}!", exercise), + Mode::Test => success!("Successfully tested {}!", exercise), + Mode::Clippy => success!("Successfully compiled {}!", exercise), + } + let no_emoji = env::var("NO_EMOJI").is_ok(); let clippy_success_msg = if no_emoji { From 17f9d7429ccd133a72e815fb5618e0ce79560929 Mon Sep 17 00:00:00 2001 From: Kisaragi <48310258+KisaragiEffective@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:10:25 +0900 Subject: [PATCH 227/476] docs: fix some code-blocks were not highlighted --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9bb8b87..11e0438a 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ This will install Rustlings and give you access to the `rustlings` command. Run In PowerShell (Run as Administrator), set `ExecutionPolicy` to `RemoteSigned`: -```ps +```ps1 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser ``` Then, you can run: -```ps +```ps1 Start-BitsTransfer -Source https://git.io/JTL5v -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 ``` From 179a75a68d03ac9518dec2297fb17f91a4fc506b Mon Sep 17 00:00:00 2001 From: x-hgg-x <39058530+x-hgg-x@users.noreply.github.com> Date: Tue, 29 Mar 2022 11:44:06 +0200 Subject: [PATCH 228/476] fix: Include exercises folder in the project structure behind a feature (#917) closes #859 closes #913 closes #942 --- Cargo.toml | 5 ++++- exercises/advanced_errors/mod.rs | 2 ++ exercises/clippy/mod.rs | 2 ++ exercises/collections/mod.rs | 4 ++++ exercises/conversions/mod.rs | 5 +++++ exercises/enums/mod.rs | 3 +++ exercises/error_handling/mod.rs | 6 ++++++ exercises/functions/mod.rs | 5 +++++ exercises/generics/mod.rs | 3 +++ exercises/if/mod.rs | 2 ++ exercises/intro/mod.rs | 2 ++ exercises/macros/mod.rs | 4 ++++ exercises/mod.rs | 26 +++++++++++++++++++++++++ exercises/modules/mod.rs | 3 +++ exercises/move_semantics/mod.rs | 5 +++++ exercises/option/mod.rs | 3 +++ exercises/primitive_types/mod.rs | 6 ++++++ exercises/standard_library_types/mod.rs | 7 +++++++ exercises/strings/mod.rs | 2 ++ exercises/structs/mod.rs | 3 +++ exercises/tests/mod.rs | 3 +++ exercises/threads/mod.rs | 1 + exercises/traits/mod.rs | 2 ++ exercises/variables/mod.rs | 6 ++++++ src/lib.rs | 3 +++ 25 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 exercises/advanced_errors/mod.rs create mode 100644 exercises/clippy/mod.rs create mode 100644 exercises/collections/mod.rs create mode 100644 exercises/conversions/mod.rs create mode 100644 exercises/enums/mod.rs create mode 100644 exercises/error_handling/mod.rs create mode 100644 exercises/functions/mod.rs create mode 100644 exercises/generics/mod.rs create mode 100644 exercises/if/mod.rs create mode 100644 exercises/intro/mod.rs create mode 100644 exercises/macros/mod.rs create mode 100644 exercises/mod.rs create mode 100644 exercises/modules/mod.rs create mode 100644 exercises/move_semantics/mod.rs create mode 100644 exercises/option/mod.rs create mode 100644 exercises/primitive_types/mod.rs create mode 100644 exercises/standard_library_types/mod.rs create mode 100644 exercises/strings/mod.rs create mode 100644 exercises/structs/mod.rs create mode 100644 exercises/tests/mod.rs create mode 100644 exercises/threads/mod.rs create mode 100644 exercises/traits/mod.rs create mode 100644 exercises/variables/mod.rs create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 30032695..4761c9a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ console = "0.7.7" notify = "4.0.15" toml = "0.4.10" regex = "1.1.6" -serde = {version = "1.0.10", features = ["derive"]} +serde = { version = "1.0.10", features = ["derive"] } [[bin]] name = "rustlings" @@ -21,3 +21,6 @@ path = "src/main.rs" assert_cmd = "0.11.0" predicates = "1.0.1" glob = "0.3.0" + +[features] +exercises = [] diff --git a/exercises/advanced_errors/mod.rs b/exercises/advanced_errors/mod.rs new file mode 100644 index 00000000..e33fb80d --- /dev/null +++ b/exercises/advanced_errors/mod.rs @@ -0,0 +1,2 @@ +mod advanced_errs1; +mod advanced_errs2; diff --git a/exercises/clippy/mod.rs b/exercises/clippy/mod.rs new file mode 100644 index 00000000..689dc95f --- /dev/null +++ b/exercises/clippy/mod.rs @@ -0,0 +1,2 @@ +mod clippy1; +mod clippy2; diff --git a/exercises/collections/mod.rs b/exercises/collections/mod.rs new file mode 100644 index 00000000..f46c1424 --- /dev/null +++ b/exercises/collections/mod.rs @@ -0,0 +1,4 @@ +mod hashmap1; +mod hashmap2; +mod vec1; +mod vec2; diff --git a/exercises/conversions/mod.rs b/exercises/conversions/mod.rs new file mode 100644 index 00000000..69f66ae4 --- /dev/null +++ b/exercises/conversions/mod.rs @@ -0,0 +1,5 @@ +mod as_ref_mut; +mod from_into; +mod from_str; +mod try_from_into; +mod using_as; diff --git a/exercises/enums/mod.rs b/exercises/enums/mod.rs new file mode 100644 index 00000000..a23fd6e5 --- /dev/null +++ b/exercises/enums/mod.rs @@ -0,0 +1,3 @@ +mod enums1; +mod enums2; +mod enums3; diff --git a/exercises/error_handling/mod.rs b/exercises/error_handling/mod.rs new file mode 100644 index 00000000..539fa23d --- /dev/null +++ b/exercises/error_handling/mod.rs @@ -0,0 +1,6 @@ +mod errors1; +mod errors2; +mod errors3; +mod errors4; +mod errors5; +mod errors6; diff --git a/exercises/functions/mod.rs b/exercises/functions/mod.rs new file mode 100644 index 00000000..445b6f58 --- /dev/null +++ b/exercises/functions/mod.rs @@ -0,0 +1,5 @@ +mod functions1; +mod functions2; +mod functions3; +mod functions4; +mod functions5; diff --git a/exercises/generics/mod.rs b/exercises/generics/mod.rs new file mode 100644 index 00000000..5b93555c --- /dev/null +++ b/exercises/generics/mod.rs @@ -0,0 +1,3 @@ +mod generics1; +mod generics2; +mod generics3; diff --git a/exercises/if/mod.rs b/exercises/if/mod.rs new file mode 100644 index 00000000..c5d02445 --- /dev/null +++ b/exercises/if/mod.rs @@ -0,0 +1,2 @@ +mod if1; +mod if2; diff --git a/exercises/intro/mod.rs b/exercises/intro/mod.rs new file mode 100644 index 00000000..445c47ab --- /dev/null +++ b/exercises/intro/mod.rs @@ -0,0 +1,2 @@ +mod intro1; +mod intro2; diff --git a/exercises/macros/mod.rs b/exercises/macros/mod.rs new file mode 100644 index 00000000..9f65acf5 --- /dev/null +++ b/exercises/macros/mod.rs @@ -0,0 +1,4 @@ +mod macros1; +mod macros2; +mod macros3; +mod macros4; diff --git a/exercises/mod.rs b/exercises/mod.rs new file mode 100644 index 00000000..6a143b56 --- /dev/null +++ b/exercises/mod.rs @@ -0,0 +1,26 @@ +mod advanced_errors; +mod clippy; +mod collections; +mod conversions; +mod enums; +mod error_handling; +mod functions; +mod generics; +mod r#if; +mod intro; +mod macros; +mod modules; +mod move_semantics; +mod option; +mod primitive_types; +mod quiz1; +mod quiz2; +mod quiz3; +mod quiz4; +mod standard_library_types; +mod strings; +mod structs; +mod tests; +mod threads; +mod traits; +mod variables; diff --git a/exercises/modules/mod.rs b/exercises/modules/mod.rs new file mode 100644 index 00000000..35f96af5 --- /dev/null +++ b/exercises/modules/mod.rs @@ -0,0 +1,3 @@ +mod modules1; +mod modules2; +mod modules3; diff --git a/exercises/move_semantics/mod.rs b/exercises/move_semantics/mod.rs new file mode 100644 index 00000000..c9e61b36 --- /dev/null +++ b/exercises/move_semantics/mod.rs @@ -0,0 +1,5 @@ +mod move_semantics1; +mod move_semantics2; +mod move_semantics3; +mod move_semantics4; +mod move_semantics5; diff --git a/exercises/option/mod.rs b/exercises/option/mod.rs new file mode 100644 index 00000000..b3cdb13d --- /dev/null +++ b/exercises/option/mod.rs @@ -0,0 +1,3 @@ +mod option1; +mod option2; +mod option3; diff --git a/exercises/primitive_types/mod.rs b/exercises/primitive_types/mod.rs new file mode 100644 index 00000000..23355239 --- /dev/null +++ b/exercises/primitive_types/mod.rs @@ -0,0 +1,6 @@ +mod primitive_types1; +mod primitive_types2; +mod primitive_types3; +mod primitive_types4; +mod primitive_types5; +mod primitive_types6; diff --git a/exercises/standard_library_types/mod.rs b/exercises/standard_library_types/mod.rs new file mode 100644 index 00000000..b03acb92 --- /dev/null +++ b/exercises/standard_library_types/mod.rs @@ -0,0 +1,7 @@ +mod arc1; +mod box1; +mod iterators1; +mod iterators2; +mod iterators3; +mod iterators4; +mod iterators5; diff --git a/exercises/strings/mod.rs b/exercises/strings/mod.rs new file mode 100644 index 00000000..b1b460bc --- /dev/null +++ b/exercises/strings/mod.rs @@ -0,0 +1,2 @@ +mod strings1; +mod strings2; diff --git a/exercises/structs/mod.rs b/exercises/structs/mod.rs new file mode 100644 index 00000000..214fed16 --- /dev/null +++ b/exercises/structs/mod.rs @@ -0,0 +1,3 @@ +mod structs1; +mod structs2; +mod structs3; diff --git a/exercises/tests/mod.rs b/exercises/tests/mod.rs new file mode 100644 index 00000000..489541be --- /dev/null +++ b/exercises/tests/mod.rs @@ -0,0 +1,3 @@ +mod tests1; +mod tests2; +mod tests3; diff --git a/exercises/threads/mod.rs b/exercises/threads/mod.rs new file mode 100644 index 00000000..24d54007 --- /dev/null +++ b/exercises/threads/mod.rs @@ -0,0 +1 @@ +mod threads1; diff --git a/exercises/traits/mod.rs b/exercises/traits/mod.rs new file mode 100644 index 00000000..6f0a9c3f --- /dev/null +++ b/exercises/traits/mod.rs @@ -0,0 +1,2 @@ +mod traits1; +mod traits2; diff --git a/exercises/variables/mod.rs b/exercises/variables/mod.rs new file mode 100644 index 00000000..a25f477e --- /dev/null +++ b/exercises/variables/mod.rs @@ -0,0 +1,6 @@ +mod variables1; +mod variables2; +mod variables3; +mod variables4; +mod variables5; +mod variables6; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..82c1e7e4 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +#[cfg(feature = "exercises")] +#[path = "../exercises/mod.rs"] +mod exercises; From 4378d1db461843d8fb93e0a8649d1c05dcb3032e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:47:50 +0000 Subject: [PATCH 229/476] 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 c9bb8b87..92a5095e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-118-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-119-orange.svg?style=flat-square)](#contributors-) # rustlings 🦀❤️ @@ -325,6 +325,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
ZX

🖋
Yang Wen

🖋
Brandon High

📖 +
x-hgg-x

💻 From 0232f6058f7d6252378f6082a46ad2f4e7885d36 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:47:51 +0000 Subject: [PATCH 230/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 8207a035..fc94bb1d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1092,6 +1092,15 @@ "contributions": [ "doc" ] + }, + { + "login": "x-hgg-x", + "name": "x-hgg-x", + "avatar_url": "https://avatars.githubusercontent.com/u/39058530?v=4", + "profile": "https://github.com/x-hgg-x", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 057d912e78dc1f465b671be4f290db49331d0701 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Mar 2022 11:49:36 +0200 Subject: [PATCH 231/476] chore: push contributors to AUTHORS.md the readme file is getting a bit crowded at this point, it's better to have a reference to AUTHORS.md, and then to let the bot add it in there --- .all-contributorsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index fc94bb1d..b18300b9 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,6 +1,6 @@ { "files": [ - "README.md" + "AUTHORS.md" ], "imageSize": 100, "commit": false, From bf93724511e672fb1dd124cb76da74f9f2af421b Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Mar 2022 11:52:06 +0200 Subject: [PATCH 232/476] chore: add empty authors file --- AUTHORS.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 AUTHORS.md diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 00000000..6d309389 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,6 @@ +## Authors + +This file lists the people that have contributed to this project. + +Excluded from this list are @carols10cents and @diannasoreil, the principal +authors. From c60bd97cb94b234a3e17d8cc043f441eca3c073e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:54:21 +0000 Subject: [PATCH 233/476] docs: update AUTHORS.md [skip ci] From 70e29d9717a1f4fdb1bdd1a52e4c4d8211262579 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:54:22 +0000 Subject: [PATCH 234/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b18300b9..c07ac794 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1101,6 +1101,15 @@ "contributions": [ "code" ] + }, + { + "login": "KisaragiEffective", + "name": "Kisaragi", + "avatar_url": "https://avatars.githubusercontent.com/u/48310258?v=4", + "profile": "http://kisaragieffective.github.io", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From 01023f5b4f461ed6819b7c3192164cee36d73b2d Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Mar 2022 14:58:52 +0200 Subject: [PATCH 235/476] chore: copy existing contributors table --- AUTHORS.md | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 6d309389..9813bd17 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -4,3 +4,165 @@ This file lists the people that have contributed to this project. Excluded from this list are @carols10cents and @diannasoreil, the principal authors. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Carol (Nichols || Goulding)

💻 🖋

QuietMisdreavus

💻 🖋

Robert M Lugg

🖋

Hynek Schlawack

💻

Katharina Fey

💻

lukabavdaz

💻 🖋

Erik Vesteraas

💻

delet0r

💻

Shaun Bennett

💻

Andrew Bagshaw

💻

Kyle Isom

💻

Colin Pitrat

💻

Zac Anger

💻

Matthias Geier

💻

Chris Pearce

💻

Yvan Sraka

💻

Denys Smirnov

💻

eddyp

💻

Brian Kung

💻 🖋

Russell

💻

Dan Wilhelm

📖

Jesse

💻 🖋

Fredrik Jambrén

💻

Pete McFarlane

🖋

nkanderson

💻 🖋

Ajax M

📖

Dylan Nugent

🖋

vyaslav

💻 🖋

George

💻

Thomas Holloway

💻 🖋

Jubilee

💻

WofWca

💻

Roberto Vidal

💻 📖 🤔 🚧

Jens

📖

Rahat Ahmed

📖

Abdou Seck

💻 🖋 👀

Katie

💻

Socrates

📖

gnodarse

🖋

Harrison Metzger

💻

Torben Jonas

💻 🖋

Paul Bissex

📖

Steven Mann

💻 🖋

Mario Reder

💻 🖋

skim

💻

Sanjay K

💻 🖋

Rohan Jain

💻

Said Aspen

💻 🖋

Ufuk Celebi

💻

lebedevsergey

📖

Aleksei Trifonov

🖋

Darren Meehan

🖋

Jihchi Lee

🖋

Christofer Bertonha

🖋

Vivek Bharath Akupatni

💻 ⚠️

Dídac Sementé Fernández

💻 🖋

Rob Story

💻

Siobhan Jacobson

💻

Evan Carroll

🖋

Jawaad Mahmood

🖋

Gaurang Tandon

🖋

Stefan Kupresak

🖋

Greg Leonard

🖋

Ryan McQuen

💻

Annika

👀

Axel Viala

💻

Mohammed Sazid Al Rashid

🖋 💻

Caleb Webber

🚧

Peter N

🚧

seancad

🚧

Will Hayworth

🖋

Christian Zeller

🖋

Jean-Francois Chevrette

🖋 💻

John Baber-Lucero

🖋

Tal

🖋

apogeeoak

🖋 💻

Larry Garfield

🖋

circumspect

🖋

Cyrus Wyett

🖋

cadolphs

💻

Pascal H.

🖋

Rod Elias

🖋

Matt Lebl

💻

Ignacio Le Fluk

🖋

Taylor Yu

💻 🖋

Patrick Hintermayer

💻

Pete Pavlovski

🖋

k12ish

🖋

Shao Yang Hong

🖋

Brandon Macer

🖋

Stoian Dan

🖋

Pi Delport

🖋

Sateesh

💻 🖋

ZC

🖋

hyperparabolic

💻

arlecchino

📖

Richthofen

💻

Ivan Nerazumov

📖

lauralindzey

📖

Rakshit Sinha

🖋

Damian

🖋

Ben Armstead

💻

anuk909

🖋 💻

granddaifuku

🖋

Weilet

🖋

LIU JIE

🖋

Antoine Büsch

💻

frogtd

🖋

Zhenghao Lu

🖋

Fredrik Enestad

🖋

xuesong

🖋

Michael Walsh

💻

alirezaghey

🖋

Franklin van Nes

💻

nekonako

💻

ZX

🖋

Yang Wen

🖋

Brandon High

📖

x-hgg-x

💻
+ + + + + + +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! From 3f0e1303e0b3bf3fecc0baced3c8b8a37f83c184 Mon Sep 17 00:00:00 2001 From: Lucas Aries <73198738+Kallu-A@users.noreply.github.com> Date: Tue, 29 Mar 2022 15:02:35 +0200 Subject: [PATCH 236/476] feat: Add move_semantics6.rs exercise (#908) --- exercises/move_semantics/move_semantics6.rs | 25 +++++++++++++++++++++ info.toml | 15 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 exercises/move_semantics/move_semantics6.rs diff --git a/exercises/move_semantics/move_semantics6.rs b/exercises/move_semantics/move_semantics6.rs new file mode 100644 index 00000000..457e7ae7 --- /dev/null +++ b/exercises/move_semantics/move_semantics6.rs @@ -0,0 +1,25 @@ +// move_semantics6.rs +// Make me compile! `rustlings hint move_semantics6` for hints +// You can't change anything except adding or removing references + +// I AM NOT DONE + +fn main() { + let data = "Rust is great!".to_string(); + + get_char(data); + + string_uppercase(&data); +} + +// Should not take ownership +fn get_char(data: String) -> char { + data.chars().last().unwrap() +} + +// Should take ownership +fn string_uppercase(mut data: &String) { + data = &data.to_uppercase(); + + println!("{}", data); +} diff --git a/info.toml b/info.toml index fbe0d53b..9430a161 100644 --- a/info.toml +++ b/info.toml @@ -237,6 +237,21 @@ in the book's section References and Borrowing': https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-references. """ +[[exercises]] +name = "move_semantics6" +path = "exercises/move_semantics/move_semantics6.rs" +mode = "compile" +hint = """ +To find the answer, you can consult the book section "References and Borrowing": +https://doc.rust-lang.org/stable/book/ch04-02-references-and-borrowing.html +The first problem is that `get_char` is taking ownership of the string. +So `data` is moved and can't be used for `string_uppercase` +`data` is moved to `get_char` first, meaning that `string_uppercase` cannot manipulate the data. +Once you've fixed that, `string_uppercase`'s function signature will also need to be adjusted. +Can you figure out how? + +Another hint: it has to do with the `&` character.""" + # PRIMITIVE TYPES [[exercises]] From 2ca5250f78cba3276b9284af5f0f49e5ce296f71 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:02:51 +0000 Subject: [PATCH 237/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 9813bd17..a7f29bb2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -157,6 +157,10 @@ authors.
Yang Wen

🖋
Brandon High

📖
x-hgg-x

💻 +
Kisaragi

📖 + + +
Lucas Aries

🖋 From d4e3d98d0abe732df08ee6fe85ef276b7805257e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:02:52 +0000 Subject: [PATCH 238/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c07ac794..24832b42 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1110,6 +1110,15 @@ "contributions": [ "doc" ] + }, + { + "login": "Kallu-A", + "name": "Lucas Aries", + "avatar_url": "https://avatars.githubusercontent.com/u/73198738?v=4", + "profile": "https://github.com/Kallu-A", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From bdf6efeccde2a669571fcc5dd68801c88c72d0f1 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 29 Mar 2022 15:04:52 +0200 Subject: [PATCH 239/476] chore: clean up readme --- README.md | 178 +++--------------------------------------------------- 1 file changed, 7 insertions(+), 171 deletions(-) diff --git a/README.md b/README.md index fdae4acb..babc3423 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ - -[![All Contributors](https://img.shields.io/badge/all_contributors-119-orange.svg?style=flat-square)](#contributors-) - - # rustlings 🦀❤️ Greetings and welcome to `rustlings`. This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages! @@ -68,6 +64,7 @@ cargo install --force --path . ``` If there are installation errors, ensure that your toolchain is up to date. For the latest, run: + ```bash rustup update ``` @@ -107,17 +104,18 @@ rustlings run next In case you get stuck, you can run the following command to get a hint for your exercise: -``` bash +```bash rustlings hint myExercise1 ``` You can also get the hint for the next unsolved exercise with the following command: -``` bash +```bash rustlings hint next ``` To check your progress, you can run the following command: + ```bash rustlings list ``` @@ -135,14 +133,14 @@ Once you've completed Rustlings, put your new knowledge to good use! Continue pr If you want to remove Rustlings from your system, there's two steps. First, you'll need to remove the exercises folder that the install script created for you: -``` bash +```bash rm -rf rustlings # or your custom folder name, if you chose and or renamed it ``` Second, since Rustlings got installed via `cargo install`, it's only reasonable to assume that you can also remove it using Cargo, and exactly that is the case. Run `cargo uninstall` to remove the `rustlings` binary: -``` bash +```bash cargo uninstall rustlings ``` @@ -172,166 +170,4 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md). ## Contributors ✨ -Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Carol (Nichols || Goulding)

💻 🖋

QuietMisdreavus

💻 🖋

Robert M Lugg

🖋

Hynek Schlawack

💻

Katharina Fey

💻

lukabavdaz

💻 🖋

Erik Vesteraas

💻

delet0r

💻

Shaun Bennett

💻

Andrew Bagshaw

💻

Kyle Isom

💻

Colin Pitrat

💻

Zac Anger

💻

Matthias Geier

💻

Chris Pearce

💻

Yvan Sraka

💻

Denys Smirnov

💻

eddyp

💻

Brian Kung

💻 🖋

Russell

💻

Dan Wilhelm

📖

Jesse

💻 🖋

Fredrik Jambrén

💻

Pete McFarlane

🖋

nkanderson

💻 🖋

Ajax M

📖

Dylan Nugent

🖋

vyaslav

💻 🖋

George

💻

Thomas Holloway

💻 🖋

Jubilee

💻

WofWca

💻

Roberto Vidal

💻 📖 🤔 🚧

Jens

📖

Rahat Ahmed

📖

Abdou Seck

💻 🖋 👀

Katie

💻

Socrates

📖

gnodarse

🖋

Harrison Metzger

💻

Torben Jonas

💻 🖋

Paul Bissex

📖

Steven Mann

💻 🖋

Mario Reder

💻 🖋

skim

💻

Sanjay K

💻 🖋

Rohan Jain

💻

Said Aspen

💻 🖋

Ufuk Celebi

💻

lebedevsergey

📖

Aleksei Trifonov

🖋

Darren Meehan

🖋

Jihchi Lee

🖋

Christofer Bertonha

🖋

Vivek Bharath Akupatni

💻 ⚠️

Dídac Sementé Fernández

💻 🖋

Rob Story

💻

Siobhan Jacobson

💻

Evan Carroll

🖋

Jawaad Mahmood

🖋

Gaurang Tandon

🖋

Stefan Kupresak

🖋

Greg Leonard

🖋

Ryan McQuen

💻

Annika

👀

Axel Viala

💻

Mohammed Sazid Al Rashid

🖋 💻

Caleb Webber

🚧

Peter N

🚧

seancad

🚧

Will Hayworth

🖋

Christian Zeller

🖋

Jean-Francois Chevrette

🖋 💻

John Baber-Lucero

🖋

Tal

🖋

apogeeoak

🖋 💻

Larry Garfield

🖋

circumspect

🖋

Cyrus Wyett

🖋

cadolphs

💻

Pascal H.

🖋

Rod Elias

🖋

Matt Lebl

💻

Ignacio Le Fluk

🖋

Taylor Yu

💻 🖋

Patrick Hintermayer

💻

Pete Pavlovski

🖋

k12ish

🖋

Shao Yang Hong

🖋

Brandon Macer

🖋

Stoian Dan

🖋

Pi Delport

🖋

Sateesh

💻 🖋

ZC

🖋

hyperparabolic

💻

arlecchino

📖

Richthofen

💻

Ivan Nerazumov

📖

lauralindzey

📖

Rakshit Sinha

🖋

Damian

🖋

Ben Armstead

💻

anuk909

🖋 💻

granddaifuku

🖋

Weilet

🖋

LIU JIE

🖋

Antoine Büsch

💻

frogtd

🖋

Zhenghao Lu

🖋

Fredrik Enestad

🖋

xuesong

🖋

Michael Walsh

💻

alirezaghey

🖋

Franklin van Nes

💻

nekonako

💻

ZX

🖋

Yang Wen

🖋

Brandon High

📖

x-hgg-x

💻
- - - - - - -This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! +Thanks goes to the wonderful people listed in [AUTHORS.md](./AUTHORS.md) 🎉 From 0bd7a0631a17a9d69af5746795a30efc9cf64e6e Mon Sep 17 00:00:00 2001 From: Soroush Zare Date: Wed, 30 Mar 2022 15:57:52 +0430 Subject: [PATCH 240/476] fix(iterators1): reorder TODO steps Update the TODO steps in the iterators1 exercise. --- exercises/standard_library_types/iterators1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/standard_library_types/iterators1.rs b/exercises/standard_library_types/iterators1.rs index 4606ad35..5aa49b64 100644 --- a/exercises/standard_library_types/iterators1.rs +++ b/exercises/standard_library_types/iterators1.rs @@ -18,7 +18,7 @@ fn main () { assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana")); assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2 assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado")); - assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2.1 - assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry")); assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3 + assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry")); + assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4 } From 4dfd85ff05bc7e624909a32ce92bfd8d68bb1669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Have=CC=81?= Date: Sun, 3 Apr 2022 23:45:45 +0200 Subject: [PATCH 241/476] fix(move_semantics) : add move_semantics6.rs to its mod --- exercises/move_semantics/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/move_semantics/mod.rs b/exercises/move_semantics/mod.rs index c9e61b36..e8eecf0a 100644 --- a/exercises/move_semantics/mod.rs +++ b/exercises/move_semantics/mod.rs @@ -3,3 +3,4 @@ mod move_semantics2; mod move_semantics3; mod move_semantics4; mod move_semantics5; +mod move_semantics6; From d114847f256c5f571c0b4c87e04b04bce3435509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Have=CC=81?= Date: Sun, 3 Apr 2022 19:49:59 +0200 Subject: [PATCH 242/476] fix(install): protect path with whitespaces using quotes and stop at the first error --- install.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 68b8da3a..1d9cff27 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -euo pipefail echo "Let's get you set up with Rustlings!" @@ -100,8 +101,8 @@ function vercomp() { RustVersion=$(rustc --version | cut -d " " -f 2) MinRustVersion=1.39 -vercomp $RustVersion $MinRustVersion -if [ $? -eq 2 ] +vercomp "$RustVersion" $MinRustVersion || ec=$? +if [ ${ec:-0} -eq 2 ] then echo "ERROR: Rust version is too old: $RustVersion - needs at least $MinRustVersion" echo "Please update Rust with 'rustup update'" @@ -112,9 +113,9 @@ fi Path=${1:-rustlings/} echo "Cloning Rustlings at $Path..." -git clone -q https://github.com/rust-lang/rustlings $Path +git clone -q https://github.com/rust-lang/rustlings "$Path" -cd $Path +cd "$Path" Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);") CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" From 89650f808af23a32c9a2c6d46592b77547a6a464 Mon Sep 17 00:00:00 2001 From: ragreenburg Date: Wed, 6 Apr 2022 00:29:27 -0700 Subject: [PATCH 243/476] fix(move_semantics2): Add comment --- exercises/move_semantics/move_semantics2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index bd21fbb7..888dc529 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -1,5 +1,5 @@ // move_semantics2.rs -// Make me compile without changing line 13! +// Make me compile without changing line 13 or moving line 10! // Execute `rustlings hint move_semantics2` for hints :) // I AM NOT DONE From d3c5058d89c08cffb8be34491147a0d8976c3b0b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Apr 2022 07:29:49 +0000 Subject: [PATCH 244/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index a7f29bb2..a81018cc 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -161,6 +161,7 @@ authors.
Lucas Aries

🖋 +
ragreenburg

🖋 From b1cdce6289934fe4a73e6f22265c13fa463208d3 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Apr 2022 07:29:50 +0000 Subject: [PATCH 245/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 24832b42..66a8eabf 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1119,6 +1119,15 @@ "contributions": [ "content" ] + }, + { + "login": "ragreenburg", + "name": "ragreenburg", + "avatar_url": "https://avatars.githubusercontent.com/u/24358100?v=4", + "profile": "https://github.com/ragreenburg", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 43d0623086edbc46fe896ba59c7afa22c3da9f7a Mon Sep 17 00:00:00 2001 From: J-S-Kim Date: Sat, 9 Apr 2022 01:23:58 +0900 Subject: [PATCH 246/476] fix(errors6.rs): remove one answer code Although marked as 'TODO', three tests pass without any implementation because the correct answer code already exists. --- exercises/error_handling/errors6.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index 0f6b27a6..847a049a 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -20,9 +20,6 @@ enum ParsePosNonzeroError { } impl ParsePosNonzeroError { - fn from_creation(err: CreationError) -> ParsePosNonzeroError { - ParsePosNonzeroError::Creation(err) - } // TODO: add another error conversion function here. } From 60bb7cc3931d21d3986ad52b2b302e632a93831c Mon Sep 17 00:00:00 2001 From: stevenfukase Date: Thu, 14 Apr 2022 17:25:44 +0900 Subject: [PATCH 247/476] Fix test (#958) fix(errors1): don't modify tests --- exercises/error_handling/errors1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 5844a497..243622c4 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -28,7 +28,7 @@ mod tests { fn generates_nametag_text_for_a_nonempty_name() { assert_eq!( generate_nametag_text("Beyoncé".into()), - Some("Hi! My name is Beyoncé".into()) + Ok("Hi! My name is Beyoncé".into()) ); } From 887b6e183b9657403553188a89aa0afaacf5ab9a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 08:26:06 +0000 Subject: [PATCH 248/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index a81018cc..5d7f5cdb 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -162,6 +162,7 @@ authors.
Lucas Aries

🖋
ragreenburg

🖋 +
stevenfukase

🖋 From 7dcc1fca29d1796608389c7b98034f27e61c9f6a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 08:26:07 +0000 Subject: [PATCH 249/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 66a8eabf..4d0e9082 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1128,6 +1128,15 @@ "contributions": [ "content" ] + }, + { + "login": "stevenfukase", + "name": "stevenfukase", + "avatar_url": "https://avatars.githubusercontent.com/u/66785624?v=4", + "profile": "https://github.com/stevenfukase", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 76a36dd38594c63b4bd64e655efeb272ccfaf2a4 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Apr 2022 10:32:43 +0200 Subject: [PATCH 250/476] chore: update errors1 comments and hint --- exercises/error_handling/errors1.rs | 8 ++------ info.toml | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 243622c4..c417fb26 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -1,9 +1,8 @@ // errors1.rs // This function refuses to generate text to be printed on a nametag if // you pass it an empty string. It'd be nicer if it explained what the problem -// was, instead of just sometimes returning `None`. The 2nd test currently -// does not compile or pass, but it illustrates the behavior we would like -// this function to have. +// was, instead of just sometimes returning `None`. Thankfully, Rust has a similar +// construct to `Option` that can be used to express error conditions. Let's use it! // Execute `rustlings hint errors1` for hints! // I AM NOT DONE @@ -21,9 +20,6 @@ pub fn generate_nametag_text(name: String) -> Option { mod tests { use super::*; - // This test passes initially if you comment out the 2nd test. - // You'll need to update what this test expects when you change - // the function under test! #[test] fn generates_nametag_text_for_a_nonempty_name() { assert_eq!( diff --git a/info.toml b/info.toml index 9430a161..56fa7ec5 100644 --- a/info.toml +++ b/info.toml @@ -490,7 +490,7 @@ name = "errors1" path = "exercises/error_handling/errors1.rs" mode = "test" hint = """ -`Err` is one of the variants of `Result`, so what the 2nd test is saying +`Ok` and `Err` are one of the variants of `Result`, so what the tests are saying is that `generate_nametag_text` should return a `Result` instead of an `Option`. @@ -500,9 +500,7 @@ To make this change, you'll need to: - change the body of the function to return `Ok(stuff)` where it currently returns `Some(stuff)` - change the body of the function to return `Err(error message)` where it - currently returns `None` - - change the first test to expect `Ok(stuff)` where it currently expects - `Some(stuff)`.""" + currently returns `None`""" [[exercises]] name = "errors2" From 4bb94e050bb19e421b69467ea49f1e221e966038 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 08:44:38 +0000 Subject: [PATCH 251/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 5d7f5cdb..1dc56475 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -163,6 +163,7 @@ authors.
Lucas Aries

🖋
ragreenburg

🖋
stevenfukase

🖋 +
J-S-Kim

🖋 From 03ba8836f2527bc30f4c86f678d91e4d4199a4bf Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Apr 2022 08:44:39 +0000 Subject: [PATCH 252/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4d0e9082..26fd5c99 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1137,6 +1137,15 @@ "contributions": [ "content" ] + }, + { + "login": "J-S-Kim", + "name": "J-S-Kim", + "avatar_url": "https://avatars.githubusercontent.com/u/17569303?v=4", + "profile": "https://github.com/J-S-Kim", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 6c87dc82102ef7cc29ce8cf6370684cfd6668d92 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Apr 2022 11:09:27 +0200 Subject: [PATCH 253/476] docs: update changelog for new release --- CHANGELOG.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcc39e42..24da1bc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,46 @@ + +## 4.7.0 (2022-04-14) + + +#### Features + +* Add move_semantics6.rs exercise (#908) ([3f0e1303](https://github.com/rust-lang/rustlings/commit/3f0e1303e0b3bf3fecc0baced3c8b8a37f83c184)) +* **intro:** Add intro section. ([21c9f441](https://github.com/rust-lang/rustlings/commit/21c9f44168394e08338fd470b5f49b1fd235986f)) +* Include exercises folder in the project structure behind a feature, enabling rust-analyzer to work (#917) ([179a75a6](https://github.com/rust-lang/rustlings/commit/179a75a68d03ac9518dec2297fb17f91a4fc506b)) + +#### Bug Fixes + +* Fix a few spelling mistakes ([1c0fe3cb](https://github.com/rust-lang/rustlings/commit/1c0fe3cbcca85f90b3985985b8e265ee872a2ab2)) +* **cli:** + * Move long text strings into constants. ([f78c4802](https://github.com/rust-lang/rustlings/commit/f78c48020830d7900dd8d81f355606581670446d)) + * Replace `filter_map()` with `find_map()` ([9b27e8d](https://github.com/rust-lang/rustlings/commit/9b27e8d993ca20232fe38a412750c3f845a83b65)) +* **clippy1:** + * Set clippy::float_cmp lint to deny (#907) ([71a06044](https://github.com/rust-lang/rustlings/commit/71a06044e6a96ff756dc31d7b0ed665ae4badb57)) + * Updated code to test correctness clippy lint with approx_constant lint rule ([f2650de3](https://github.com/rust-lang/rustlings/commit/f2650de369810867d2763e935ac0963c32ec420e)) +* **errors1:** + * Add a comment to make the purpose more clear (#486) ([cbcde345](https://github.com/rust-lang/rustlings/commit/cbcde345409c3e550112e449242848eaa3391bb6)) + * Don't modify tests (#958) ([60bb7cc](https://github.com/rust-lang/rustlings/commit/60bb7cc3931d21d3986ad52b2b302e632a93831c)) +* **errors6:** Remove existing answer code ([43d0623](https://github.com/rust-lang/rustlings/commit/43d0623086edbc46fe896ba59c7afa22c3da9f7a)) +* **functions5:** Remove wrong new line and small English improvements (#885) ([8ef4869b](https://github.com/rust-lang/rustlings/commit/8ef4869b264094e5a9b50452b4534823a9df19c3)) +* **install:** protect path with whitespaces using quotes and stop at the first error ([d114847f](https://github.com/rust-lang/rustlings/commit/d114847f256c5f571c0b4c87e04b04bce3435509)) +* **intro1:** Add compiler error explanation. ([9b8de655](https://github.com/rust-lang/rustlings/commit/9b8de65525a5576b78cf0c8e4098cdd34296338f)) +* **iterators1:** reorder TODO steps ([0bd7a063](https://github.com/rust-lang/rustlings/commit/0bd7a0631a17a9d69af5746795a30efc9cf64e6e)) +* **move_semantics2:** Add comment ([89650f80](https://github.com/rust-lang/rustlings/commit/89650f808af23a32c9a2c6d46592b77547a6a464)) +* **move_semantics5:** correct typo (#857) ([46c28d5c](https://github.com/rust-lang/rustlings/commit/46c28d5cef3d8446b5a356b19d8dbc725f91a3a0)) +* **quiz1:** update to say quiz covers "If" ([1622e8c1](https://github.com/rust-lang/rustlings/commit/1622e8c198d89739765c915203efff0091bdeb78)) +* **structs3:** + * Add a hint for panic (#608) ([4f7ff5d9](https://github.com/rust-lang/rustlings/commit/4f7ff5d9c7b2d8b045194c1a9469d37e30257c4a)) + * remove redundant 'return' (#852) ([bf33829d](https://github.com/rust-lang/rustlings/commit/bf33829da240375d086f96267fc2e02fa6b07001)) + * Assigned value to `cents_per_gram` in test ([d1ee2da](https://github.com/rust-lang/rustlings/commit/d1ee2daf14f19105e6db3f9c610f44293d688532)) +* **structs3.rs:** assigned value to cents_per_gram in test ([d1ee2daf](https://github.com/rust-lang/rustlings/commit/d1ee2daf14f19105e6db3f9c610f44293d688532)) +* **traits1:** rename test functions to snake case (#854) ([1663a16e](https://github.com/rust-lang/rustlings/commit/1663a16eade6ca646b6ed061735f7982434d530d)) + +#### Documentation improvements + +* Add hints on how to get GCC installed (#741) ([bc56861](https://github.com/rust-lang/rustlings/commit/bc5686174463ad6f4f6b824b0e9b97c3039d4886)) +* Fix some code blocks that were not highlighted ([17f9d74](https://github.com/rust-lang/rustlings/commit/17f9d7429ccd133a72e815fb5618e0ce79560929)) + + ## 4.6.0 (2021-09-25) From 8f33dba9caaf59d19a174d39ec0373241807eb6e Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Apr 2022 11:15:04 +0200 Subject: [PATCH 254/476] docs: write documentation for enabling rust-analyzer --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index babc3423..876578ee 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,27 @@ rustlings list After every couple of sections, there will be a quiz that'll test your knowledge on a bunch of sections at once. These quizzes are found in `exercises/quizN.rs`. +## Enabling `rust-analyzer` + +`rust-analyzer` support is provided, but it depends on your editor +whether it's enabled by default. (RLS support is not provided) + +To enable `rust-analyzer`, you'll need to make Cargo build the project +with the `exercises` feature, which will automatically include the `exercises/` +subfolder in the project. The easiest way to do this is to tell your editor to +build the project with all features (the equivalent of `cargo build --all-features`). +For specific editor instructions: + +- **VSCode**: Add a `.vscode/settings.json` file with the following: +```json +{ + "rust-analyzer.cargo.features": ["exercises"] +} +``` +- **IntelliJ-based Editors**: Using the Rust plugin, everything should work + by default. +- _Missing your editor? Feel free to contribute more instructions!_ + ## Continuing On Once you've completed Rustlings, put your new knowledge to good use! Continue practicing your Rust skills by building your own projects, contributing to Rustlings, or finding other open-source projects to contribute to. From cf9f382873a8ec167803ff575004048240dc0532 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Apr 2022 11:16:00 +0200 Subject: [PATCH 255/476] chore: bump version --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e536d1b7..c3e8290f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -541,7 +541,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.6.0" +version = "4.7.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 4761c9a4..a340cd21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustlings" -version = "4.6.0" -authors = ["anastasie ", "Carol (Nichols || Goulding) "] +version = "4.7.0" +authors = ["mokou ", "Carol (Nichols || Goulding) "] edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 453b8c0b..e8591f7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.6.0"; +const VERSION: &str = "4.7.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From 0b7f3fe37a6f202d85607ae30d07736a9202d489 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Apr 2022 11:19:54 +0200 Subject: [PATCH 256/476] test: skip mod.rs files when checking for annotations --- tests/integration_tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index be9af965..fc46b983 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -125,6 +125,9 @@ fn get_hint_for_single_test() { fn all_exercises_require_confirmation() { for exercise in glob("exercises/**/*.rs").unwrap() { let path = exercise.unwrap(); + if path.file_name().unwrap() == "mod.rs" { + continue + } let source = { let mut file = File::open(&path).unwrap(); let mut s = String::new(); From 92a5d0037f0124eb2cdd8637762ca6aa4494fcbd Mon Sep 17 00:00:00 2001 From: fointard Date: Tue, 19 Apr 2022 17:11:27 +0200 Subject: [PATCH 257/476] refactor(arc1): improve readability by using functional style --- exercises/standard_library_types/arc1.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index d167380c..f60061e7 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -32,12 +32,7 @@ fn main() { for offset in 0..8 { let child_numbers = // TODO joinhandles.push(thread::spawn(move || { - let mut i = offset; - let mut sum = 0; - while i < child_numbers.len() { - sum += child_numbers[i]; - i += 8; - } + let sum: u32 = child_numbers.iter().filter(|n| *n % 8 == offset).sum(); println!("Sum of offset {} is {}", offset, sum); })); } From 452ab26aa735c85756ca0ec91453fe72d487af1b Mon Sep 17 00:00:00 2001 From: fointard Date: Tue, 19 Apr 2022 17:37:00 +0200 Subject: [PATCH 258/476] refactor(using_as): improve readability by using sum() instead of fold() --- exercises/conversions/using_as.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 821309ec..f3f745ff 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -8,7 +8,7 @@ // I AM NOT DONE fn average(values: &[f64]) -> f64 { - let total = values.iter().fold(0.0, |a, b| a + b); + let total = values.iter().sum::(); total / values.len() } From 107f1f97d96cb79513a7ff62d92e52c4296a69e8 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 07:14:26 +0000 Subject: [PATCH 259/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 1dc56475..9b388bb4 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -164,6 +164,7 @@ authors.
ragreenburg

🖋
stevenfukase

🖋
J-S-Kim

🖋 +
Fointard

🖋 From c9b73e412ed49f05c999a3ecf640209d5700dfac Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 20 Apr 2022 07:14:27 +0000 Subject: [PATCH 260/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 26fd5c99..d3f0c2ce 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1146,6 +1146,15 @@ "contributions": [ "content" ] + }, + { + "login": "Fointard", + "name": "Fointard", + "avatar_url": "https://avatars.githubusercontent.com/u/9333398?v=4", + "profile": "https://github.com/Fointard", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 268822dbd833435673889f6da04020d20b30acb8 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 20 Apr 2022 09:20:42 +0200 Subject: [PATCH 261/476] chore: bump minimum required rust version in installs --- install.ps1 | 2 +- install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install.ps1 b/install.ps1 index 32167f06..97980c5b 100644 --- a/install.ps1 +++ b/install.ps1 @@ -53,7 +53,7 @@ function vercomp($v1, $v2) { } $rustVersion = $(rustc --version).Split(" ")[1] -$minRustVersion = "1.39" +$minRustVersion = "1.56" if ((vercomp $rustVersion $minRustVersion) -eq 2) { Write-Host "WARNING: Rust version is too old: $rustVersion - needs at least $minRustVersion" Write-Host "Please update Rust with 'rustup update'" diff --git a/install.sh b/install.sh index 1d9cff27..bf517851 100755 --- a/install.sh +++ b/install.sh @@ -100,7 +100,7 @@ function vercomp() { } RustVersion=$(rustc --version | cut -d " " -f 2) -MinRustVersion=1.39 +MinRustVersion=1.56 vercomp "$RustVersion" $MinRustVersion || ec=$? if [ ${ec:-0} -eq 2 ] then From c811643d1e28dc573c5862ccfd4901d6860f5855 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 20 Apr 2022 09:35:08 +0200 Subject: [PATCH 262/476] chore: bump library versions --- Cargo.lock | 140 +++++--------------------------------------------- Cargo.toml | 14 ++--- src/run.rs | 4 +- src/verify.rs | 8 +-- 4 files changed, 27 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c3e8290f..ce894363 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,17 +52,6 @@ dependencies = [ "predicates-tree", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi 0.3.9", -] - [[package]] name = "autocfg" version = "1.0.1" @@ -87,45 +76,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clicolors-control" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e" -dependencies = [ - "atty", - "lazy_static", - "libc", - "winapi 0.3.9", -] - [[package]] name = "console" -version = "0.7.7" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" -dependencies = [ - "atty", - "clicolors-control", - "encode_unicode", - "lazy_static", - "libc", - "parking_lot", - "regex", - "termios", - "unicode-width", - "winapi 0.3.9", -] - -[[package]] -name = "console" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" +checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" dependencies = [ "encode_unicode", - "lazy_static", "libc", + "once_cell", "regex", "terminal_size", "unicode-width", @@ -227,25 +186,15 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "indicatif" -version = "0.10.3" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" +checksum = "2d207dc617c7a380ab07ff572a6e52fa202a2a8f355860ac9c38e23f8196be1b" dependencies = [ - "console 0.14.1", + "console", "lazy_static", "number_prefix", - "parking_lot", "regex", ] @@ -269,15 +218,6 @@ dependencies = [ "libc", ] -[[package]] -name = "instant" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "iovec" version = "0.1.4" @@ -321,15 +261,6 @@ version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1fa8cddc8fbbee11227ef194b5317ed014b8acbf15139bd716a18ad3fe99ec5" -[[package]] -name = "lock_api" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.14" @@ -434,37 +365,15 @@ dependencies = [ [[package]] name = "number_prefix" -version = "0.2.8" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" -dependencies = [ - "num-traits", -] +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] -name = "parking_lot" -version = "0.11.1" +name = "once_cell" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi 0.3.9", -] +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" [[package]] name = "predicates" @@ -545,7 +454,7 @@ version = "4.7.0" dependencies = [ "argh", "assert_cmd", - "console 0.7.7", + "console", "glob", "indicatif", "notify", @@ -570,12 +479,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.129" @@ -613,12 +516,6 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" -[[package]] -name = "smallvec" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" - [[package]] name = "syn" version = "1.0.75" @@ -640,20 +537,11 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "termios" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" -dependencies = [ - "libc", -] - [[package]] name = "toml" -version = "0.4.10" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index a340cd21..e8ded146 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,13 +5,13 @@ authors = ["mokou ", "Carol (Nichols || Goulding) Result<(), ()> { // This is strictly for non-test binaries, so output is displayed fn compile_and_run(exercise: &Exercise) -> Result<(), ()> { let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); + progress_bar.set_message(format!("Compiling {}...", exercise)); progress_bar.enable_steady_tick(100); let compilation_result = exercise.compile(); @@ -37,7 +37,7 @@ fn compile_and_run(exercise: &Exercise) -> Result<(), ()> { } }; - progress_bar.set_message(format!("Running {}...", exercise).as_str()); + progress_bar.set_message(format!("Running {}...", exercise)); let result = compilation.run(); progress_bar.finish_and_clear(); diff --git a/src/verify.rs b/src/verify.rs index fd59fa51..eff57141 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -39,7 +39,7 @@ pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> { // Invoke the rust compiler without running the resulting binary fn compile_only(exercise: &Exercise) -> Result { let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); + progress_bar.set_message(format!("Compiling {}...", exercise)); progress_bar.enable_steady_tick(100); let _ = compile(exercise, &progress_bar)?; @@ -52,12 +52,12 @@ fn compile_only(exercise: &Exercise) -> Result { // Compile the given Exercise and run the resulting binary in an interactive mode fn compile_and_run_interactively(exercise: &Exercise) -> Result { let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); + progress_bar.set_message(format!("Compiling {}...", exercise)); progress_bar.enable_steady_tick(100); let compilation = compile(exercise, &progress_bar)?; - progress_bar.set_message(format!("Running {}...", exercise).as_str()); + progress_bar.set_message(format!("Running {}...", exercise)); let result = compilation.run(); progress_bar.finish_and_clear(); @@ -80,7 +80,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { // the output if verbose is set to true fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool) -> Result { let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Testing {}...", exercise).as_str()); + progress_bar.set_message(format!("Testing {}...", exercise)); progress_bar.enable_steady_tick(100); let compilation = compile(exercise, &progress_bar)?; From 9ec35d899ce4002b6e1703185dd1f5243d80e30a Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 20 Apr 2022 09:44:37 +0200 Subject: [PATCH 263/476] chore: bump version Plus, remove the clog configuration file, since that's not being used anymore. --- .clog.toml | 4 ---- CHANGELOG.md | 21 +++++++++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) delete mode 100644 .clog.toml diff --git a/.clog.toml b/.clog.toml deleted file mode 100644 index 206c3b5a..00000000 --- a/.clog.toml +++ /dev/null @@ -1,4 +0,0 @@ -[clog] - -repository = "https://github.com/rust-lang/rustlings" -changelog = "CHANGELOG.md" \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 24da1bc0..e857e339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ + +## 4.7.1 (2022-04-20) + +#### Features + +- The amount of dependency crates that need to be compiled went down from ~65 to + ~45 by bumping dependency versions. +- The minimum Rust version in the install scripts has been bumped to 1.56.0 (this isn't in + the release itself, since install scripts don't really get versioned) + +#### Bug Fixes + +- **arc1**: A small part has been rewritten using a more functional code style (#968). +- **using_as**: A small part has been refactored to use `sum` instead of `fold`, resulting + in better readability. + +#### Housekeeping + +- The changelog will now be manually written instead of being automatically generated by the + Git log. + ## 4.7.0 (2022-04-14) diff --git a/Cargo.lock b/Cargo.lock index ce894363..27521e7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -450,7 +450,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.7.0" +version = "4.7.1" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index e8ded146..befdd6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.7.0" +version = "4.7.1" authors = ["mokou ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index e8591f7d..83b98d96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.7.0"; +const VERSION: &str = "4.7.1"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From d2179d3e8442ca3ecd24738e2fa41b31023120e5 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 20 Apr 2022 09:47:43 +0200 Subject: [PATCH 264/476] doc: update manual checkout version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 876578ee..f954618b 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,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.6.0) -git clone -b 4.6.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.7.1) +git clone -b 4.7.1 --depth 1 https://github.com/rust-lang/rustlings cd rustlings cargo install --force --path . ``` From 8dc696883ee8f7c0eb6da75cdcc7b58f40872e15 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 09:36:52 +0000 Subject: [PATCH 265/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 9b388bb4..ad8ce474 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -165,6 +165,7 @@ authors.
stevenfukase

🖋
J-S-Kim

🖋
Fointard

🖋 +
Ryan Lowe

💻 From 283a4691aa7155cb896650abcf962066d12cb0d6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 09:36:53 +0000 Subject: [PATCH 266/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d3f0c2ce..d995be80 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1155,6 +1155,15 @@ "contributions": [ "content" ] + }, + { + "login": "rytheo", + "name": "Ryan Lowe", + "avatar_url": "https://avatars.githubusercontent.com/u/22184325?v=4", + "profile": "https://github.com/rytheo", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From b821ffdd332b7359317c88cb4e6fa9a6d290640e Mon Sep 17 00:00:00 2001 From: Ron Lusk Date: Fri, 22 Apr 2022 09:04:36 -0400 Subject: [PATCH 267/476] docs(move_semantics5): Replace "in vogue" with "in scope" in hint The hint for `move_semantics5` refers to "the range in which each mutable reference is in vogue". Unless this is a deliberate introduction of "vogue" (an admittedly-useful term because "scope" isn't purely lexical, as in many other languages), it may be in error: I have been unable to find the term used with reference to *Rust* references. Thus, I'm suggesting the replacement, in case it's been overlooked. --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 56fa7ec5..54a91bfb 100644 --- a/info.toml +++ b/info.toml @@ -231,7 +231,7 @@ path = "exercises/move_semantics/move_semantics5.rs" mode = "compile" hint = """ Carefully reason about the range in which each mutable reference is in -vogue. Does it help to update the value of referent (x) immediately after +scope. 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. From 701dd9c7008f6607f0fab67dc6b44f1294ae9586 Mon Sep 17 00:00:00 2001 From: cuishuang Date: Sat, 23 Apr 2022 21:01:40 +0800 Subject: [PATCH 268/476] fix typo Signed-off-by: cuishuang --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e857e339..1fc12506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -285,7 +285,7 @@ #### Features * add Option2 exercise (#290) ([86b5c08b](https://github.com/rust-lang/rustlings/commit/86b5c08b9bea1576127a7c5f599f5752072c087d)) -* add excercise for option (#282) ([135e5d47](https://github.com/rust-lang/rustlings/commit/135e5d47a7c395aece6f6022117fb20c82f2d3d4)) +* add exercise for option (#282) ([135e5d47](https://github.com/rust-lang/rustlings/commit/135e5d47a7c395aece6f6022117fb20c82f2d3d4)) * add new exercises for generics (#280) ([76be5e4e](https://github.com/rust-lang/rustlings/commit/76be5e4e991160f5fd9093f03ee2ba260e8f7229)) * **ci:** add buildkite config ([b049fa2c](https://github.com/rust-lang/rustlings/commit/b049fa2c84dba0f0c8906ac44e28fd45fba51a71)) From 7eb66550c99997d65ac68906521193243ddaa50e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 09:36:30 +0000 Subject: [PATCH 269/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index ad8ce474..30efeeb6 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -166,6 +166,7 @@ authors.
J-S-Kim

🖋
Fointard

🖋
Ryan Lowe

💻 +
cui fliter

🖋 From 190bb27d78f264126ad5dd1e19f191348ac7e370 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 09:36:31 +0000 Subject: [PATCH 270/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d995be80..b9a7aa4c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1164,6 +1164,15 @@ "contributions": [ "code" ] + }, + { + "login": "cuishuang", + "name": "cui fliter", + "avatar_url": "https://avatars.githubusercontent.com/u/15921519?v=4", + "profile": "http://www.dashen.tech", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 9e98b78260c5fba20484533d5b6f0ddbec2a2dd4 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 09:38:18 +0000 Subject: [PATCH 271/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 30efeeb6..169430fe 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -167,6 +167,7 @@ authors.
Fointard

🖋
Ryan Lowe

💻
cui fliter

🖋 +
Ron Lusk

🖋 From 7a41bbca67935ae0012d145f90c8519b3394f744 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 09:38:19 +0000 Subject: [PATCH 272/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b9a7aa4c..94fef728 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1173,6 +1173,15 @@ "contributions": [ "content" ] + }, + { + "login": "luskwater", + "name": "Ron Lusk", + "avatar_url": "https://avatars.githubusercontent.com/u/42529?v=4", + "profile": "https://github.com/luskwater", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 13832d772646b149368e0470ad65ca0fa3722540 Mon Sep 17 00:00:00 2001 From: Bryan Lee Date: Wed, 27 Apr 2022 00:51:25 +0800 Subject: [PATCH 273/476] docs: replace git.io link with the original URL --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f954618b..fd2d4e42 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ You will need to have Rust installed. You can get it by visiting https://rustup. Just run: ```bash -curl -L https://git.io/install-rustlings | bash +curl -L https://raw.githubusercontent.com/rust-lang/rustlings/master/install.sh | bash # Or if you want it to be installed to a different path: -curl -L https://git.io/install-rustlings | bash -s mypath/ +curl -L https://raw.githubusercontent.com/rust-lang/rustlings/master/install.sh | bash -s mypath/ ``` This will install Rustlings and give you access to the `rustlings` command. Run it to get started! @@ -39,7 +39,7 @@ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser Then, you can run: ```ps1 -Start-BitsTransfer -Source https://git.io/JTL5v -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 +Start-BitsTransfer -Source https://raw.githubusercontent.com/rust-lang/rustlings/main/install.ps1 -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1 ``` To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. From 659a99032e265a94c0bf9cca12416a404a2cb252 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 27 Apr 2022 12:21:54 +0200 Subject: [PATCH 274/476] chore: change branch name to main for cloning --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd2d4e42..5febd651 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ You will need to have Rust installed. You can get it by visiting https://rustup. Just run: ```bash -curl -L https://raw.githubusercontent.com/rust-lang/rustlings/master/install.sh | bash +curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash # Or if you want it to be installed to a different path: -curl -L https://raw.githubusercontent.com/rust-lang/rustlings/master/install.sh | bash -s mypath/ +curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash -s mypath/ ``` This will install Rustlings and give you access to the `rustlings` command. Run it to get started! From 144e1ef01821e8d3c14a0d06874c6d4fcd597693 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:22:19 +0000 Subject: [PATCH 275/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 169430fe..4ce36b6a 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -169,6 +169,9 @@ authors.
cui fliter

🖋
Ron Lusk

🖋 + +
Bryan Lee

🖋 + From a18f3b8158aaafebcaae2078c968d738ef7389b0 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:22:20 +0000 Subject: [PATCH 276/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 94fef728..d90e92c7 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1182,6 +1182,15 @@ "contributions": [ "content" ] + }, + { + "login": "liby", + "name": "Bryan Lee", + "avatar_url": "https://avatars.githubusercontent.com/u/38807139?v=4", + "profile": "http://liby.github.io/liby/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 7027320a8f09d5047c7349635eca7c41bcfe2aec Mon Sep 17 00:00:00 2001 From: likzn <1020193211@qq.com> Date: Wed, 4 May 2022 00:46:49 +0800 Subject: [PATCH 277/476] fix(install.sh):fix arr out of bounds --- install.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/install.sh b/install.sh index bf517851..7d8ac90c 100755 --- a/install.sh +++ b/install.sh @@ -75,6 +75,21 @@ function vercomp() { then max_len=$len2 fi + + #pad right in short arr + if [[ len1 -gt len2 ]]; + then + for ((i = len2; i < len1; i++)); + do + v2[$i]=0 + done + else + for ((i = len1; i < len2; i++)); + do + v1[$i]=0 + done + fi + for i in `seq 0 $max_len` do # Fill empty fields with zeros in v1 From 769483640c6cb5b00f1be10ec3c7f2d0873a6562 Mon Sep 17 00:00:00 2001 From: Nandaja Varma Date: Mon, 9 May 2022 19:20:04 +0000 Subject: [PATCH 278/476] remove deprecated user uploaded extension from .gitpod.yml --- .gitpod.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 46b1a6a8..73cb802d 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -4,4 +4,4 @@ tasks: vscode: extensions: - - rust-lang.rust@0.7.8:CvNqMTgDdt3UXt+6BCDTVg== + - rust-lang.rust@0.7.8 diff --git a/README.md b/README.md index 5febd651..dd96a59c 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ When you get a permission denied message then you have to exclude the directory [Run on Repl.it](https://repl.it/github/rust-lang/rustlings) -[Open in Gitpod](https://gitpod.io/#https://github.com/rust-lang/rustlings) +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/rust-lang/rustlings) ## Manually From b8ff2993999ef3f7b2243f3ce080b66a9d2b1219 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 10 May 2022 10:45:13 +0000 Subject: [PATCH 279/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 4ce36b6a..cb997bea 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -171,6 +171,7 @@ authors.
Bryan Lee

🖋 +
Nandaja Varma

📖 From 89efbdf02d5525733493c341aa03bb3b8ecace19 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 10 May 2022 10:45:14 +0000 Subject: [PATCH 280/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d90e92c7..03c84b70 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1191,6 +1191,15 @@ "contributions": [ "content" ] + }, + { + "login": "nandajavarma", + "name": "Nandaja Varma", + "avatar_url": "https://avatars.githubusercontent.com/u/2624550?v=4", + "profile": "http://nandaja.space", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 8, From 5b940165852772d9a009f2f7db50f0a1bda8fd9d Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Tue, 17 May 2022 17:24:39 +0800 Subject: [PATCH 281/476] check for rustup install --- install.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 7d8ac90c..f3b3f33d 100755 --- a/install.sh +++ b/install.sh @@ -25,12 +25,21 @@ else exit 1 fi +if [ -x "$(command -v rustup)" ] +then + echo "SUCCESS: rustup is installed" +else + echo "ERROR: rustup does not seem to be installed." + echo "Please download rustup using https://rustup.rs!" + exit 1 +fi + if [ -x "$(command -v rustc)" ] then echo "SUCCESS: Rust is installed" else echo "ERROR: Rust does not seem to be installed." - echo "Please download Rust using https://rustup.rs!" + echo "Please download Rust using rustup!" exit 1 fi @@ -39,7 +48,7 @@ then echo "SUCCESS: Cargo is installed" else echo "ERROR: Cargo does not seem to be installed." - echo "Please download Rust and Cargo using https://rustup.rs!" + echo "Please download Rust and Cargo using rustup!" exit 1 fi From c17177bdefb696611fecd6400fa6eed831eb69fc Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 17 May 2022 11:21:33 +0000 Subject: [PATCH 282/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index cb997bea..728481ce 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -172,6 +172,7 @@ authors.
Bryan Lee

🖋
Nandaja Varma

📖 +
pwygab

💻 From 47afcdcc6b74409102d31390de508e9db4405376 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 17 May 2022 11:21:34 +0000 Subject: [PATCH 283/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 03c84b70..4d2034e7 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1200,6 +1200,15 @@ "contributions": [ "doc" ] + }, + { + "login": "merelymyself", + "name": "pwygab", + "avatar_url": "https://avatars.githubusercontent.com/u/88221256?v=4", + "profile": "https://github.com/merelymyself", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From b0e079e6bf7963aa9acbd94ac0b190cd93b6f301 Mon Sep 17 00:00:00 2001 From: Lucas Grigolon Varela <37870368+lucasgrvarela@users.noreply.github.com> Date: Fri, 20 May 2022 20:26:37 -0300 Subject: [PATCH 284/476] Update info.toml --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 54a91bfb..32e0d9ab 100644 --- a/info.toml +++ b/info.toml @@ -21,7 +21,7 @@ name = "variables1" path = "exercises/variables/variables1.rs" mode = "compile" hint = """ -Hint: The declaration on line 12 is missing a keyword that is needed in Rust +Hint: The declaration on line 8 is missing a keyword that is needed in Rust to create a new variable binding.""" [[exercises]] From fedabf5f7f89ba4a99e52fe55c5b85f04245c139 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 21 May 2022 14:30:12 +0000 Subject: [PATCH 285/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 728481ce..4853c717 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -173,6 +173,7 @@ authors.
Bryan Lee

🖋
Nandaja Varma

📖
pwygab

💻 +
Lucas Grigolon Varela

🖋 From 439a07445e167de4699f56ffe3c2945e8065c770 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 21 May 2022 14:30:14 +0000 Subject: [PATCH 286/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4d2034e7..295a7d4c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1209,6 +1209,15 @@ "contributions": [ "code" ] + }, + { + "login": "lucasgrvarela", + "name": "Lucas Grigolon Varela", + "avatar_url": "https://avatars.githubusercontent.com/u/37870368?v=4", + "profile": "http://linkedin.com/in/lucasgrvarela", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 0bdb5207b5ea0ae83c2571a1bb16203381936b2e Mon Sep 17 00:00:00 2001 From: Jesse van Papenrecht Date: Sun, 22 May 2022 18:56:26 +0200 Subject: [PATCH 287/476] typo fix in hint message if2 --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 32e0d9ab..efe2b9c7 100644 --- a/info.toml +++ b/info.toml @@ -158,7 +158,7 @@ path = "exercises/if/if2.rs" mode = "test" hint = """ For that first compiler error, it's important in Rust that each conditional -block return the same type! To get the tests passing, you will need a couple +block returns the same type! To get the tests passing, you will need a couple conditions checking different input values.""" # TEST 1 From 34a3c440d0efb172594574ca3ac98bafe2233323 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 13:56:59 +0000 Subject: [PATCH 288/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 4853c717..a4b6bdf2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -174,6 +174,7 @@ authors.
Nandaja Varma

📖
pwygab

💻
Lucas Grigolon Varela

🖋 +
Bufo

🖋 From ffb6ecaf7eb6f2909d7c03e667cdbd80fe77bd5b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 13:57:00 +0000 Subject: [PATCH 289/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 295a7d4c..00566c7e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1218,6 +1218,15 @@ "contributions": [ "content" ] + }, + { + "login": "bufo24", + "name": "Bufo", + "avatar_url": "https://avatars.githubusercontent.com/u/32884105?v=4", + "profile": "https://github.com/bufo24", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 5130a57f8fe6093168759c5328c41a2f839ea7e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:06:16 +0000 Subject: [PATCH 290/476] chore(deps): bump regex from 1.5.4 to 1.5.5 Bumps [regex](https://github.com/rust-lang/regex) from 1.5.4 to 1.5.5. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.5.4...1.5.5) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27521e7c..02b78eca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -433,9 +433,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.4" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ "aho-corasick", "memchr", From baca5d62aebdac65c691f28f2f306be83662c863 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 13 Jun 2022 21:30:25 +0200 Subject: [PATCH 291/476] fix: update link to book --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index efe2b9c7..a9608e65 100644 --- a/info.toml +++ b/info.toml @@ -84,7 +84,7 @@ than keyword 'let'. Constants types must also always be annotated. Read more about constants under 'Differences Between Variables and Constants' in the book's section 'Variables and Mutability': -https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants +https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#constants """ # FUNCTIONS From be87cc9fa624233a8bf2f489399f7837e2601bd3 Mon Sep 17 00:00:00 2001 From: Jack Clayton Date: Thu, 16 Jun 2022 11:53:41 +0800 Subject: [PATCH 292/476] Add lsp command to fix rust-analyzer --- .gitignore | 1 + Cargo.lock | 19 ++++++++--- Cargo.toml | 3 ++ README.md | 19 +---------- src/main.rs | 31 +++++++++++++++++ src/project.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 src/project.rs diff --git a/.gitignore b/.gitignore index 253f8f33..253d85bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target/ *.pdb exercises/clippy/Cargo.toml exercises/clippy/Cargo.lock +rust-project.json .idea .vscode *.iml diff --git a/Cargo.lock b/Cargo.lock index 02b78eca..6737d29c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,6 +186,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "home" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "indicatif" version = "0.16.2" @@ -229,9 +238,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "kernel32-sys" @@ -456,11 +465,13 @@ dependencies = [ "assert_cmd", "console", "glob", + "home", "indicatif", "notify", "predicates", "regex", "serde", + "serde_json", "toml", ] @@ -501,9 +512,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.66" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa", "ryu", diff --git a/Cargo.toml b/Cargo.toml index befdd6e8..e2a05aae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,9 @@ notify = "4.0" toml = "0.5" regex = "1.5" serde= { version = "1.0", features = ["derive"] } +serde_json = "1.0.81" +home = "0.5.3" +glob = "0.3.0" [[bin]] name = "rustlings" diff --git a/README.md b/README.md index dd96a59c..12a77810 100644 --- a/README.md +++ b/README.md @@ -126,24 +126,7 @@ After every couple of sections, there will be a quiz that'll test your knowledge ## Enabling `rust-analyzer` -`rust-analyzer` support is provided, but it depends on your editor -whether it's enabled by default. (RLS support is not provided) - -To enable `rust-analyzer`, you'll need to make Cargo build the project -with the `exercises` feature, which will automatically include the `exercises/` -subfolder in the project. The easiest way to do this is to tell your editor to -build the project with all features (the equivalent of `cargo build --all-features`). -For specific editor instructions: - -- **VSCode**: Add a `.vscode/settings.json` file with the following: -```json -{ - "rust-analyzer.cargo.features": ["exercises"] -} -``` -- **IntelliJ-based Editors**: Using the Rust plugin, everything should work - by default. -- _Missing your editor? Feel free to contribute more instructions!_ +Run the command `rustlings lsp` which will generate a `rust-project.json` at the root of the project, this allows [rust-analyzer](https://rust-analyzer.github.io/) to parse each exercise. ## Continuing On diff --git a/src/main.rs b/src/main.rs index af3dffbc..24ffbc5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use crate::exercise::{Exercise, ExerciseList}; +use crate::project::RustAnalyzerProject; use crate::run::run; use crate::verify::verify; use argh::FromArgs; @@ -20,6 +21,7 @@ use std::time::Duration; mod ui; mod exercise; +mod project; mod run; mod verify; @@ -47,6 +49,7 @@ enum Subcommands { Run(RunArgs), Hint(HintArgs), List(ListArgs), + Lsp(LspArgs), } #[derive(FromArgs, PartialEq, Debug)] @@ -77,6 +80,12 @@ struct HintArgs { name: String, } +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "lsp")] +/// Enable rust-analyzer for exercises +struct LspArgs {} + + #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "list")] /// Lists the exercises available in Rustlings @@ -206,6 +215,25 @@ fn main() { verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1)); } + Subcommands::Lsp(_subargs) => { + let mut project = RustAnalyzerProject::new(); + project + .get_sysroot_src() + .expect("Couldn't find toolchain path, do you have `rustc` installed?"); + project + .exercies_to_json() + .expect("Couldn't parse rustlings exercises files"); + + if project.crates.is_empty() { + println!("Failed find any exercises, make sure you're in the `rustlings` folder"); + } else if project.write_to_disk().is_err() { + println!("Failed to write rust-project.json to disk for rust-analyzer"); + } else { + println!("Successfully generated rust-project.json"); + println!("rust-analyzer will now parse exercises, restart your language server or editor") + } + } + Subcommands::Watch(_subargs) => match watch(&exercises, verbose) { Err(e) => { println!("Error: Could not watch your progress. Error message was {:?}.", e); @@ -224,6 +252,7 @@ fn main() { } } + fn spawn_watch_shell(failed_exercise_hint: &Arc>>, should_quit: Arc) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here."); @@ -367,6 +396,8 @@ started, here's a couple of notes about how Rustlings operates: 4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub! (https://github.com/rust-lang/rustlings/issues/new). We look at every issue, and sometimes, other learners do too so you can help each other out! +5. If you want to use `rust-analyzer` with exercises, which provides features like + autocompletion, run the command `rustlings lsp`. Got all that? Great! To get started, run `rustlings watch` in order to get the first exercise. Make sure to have your editor open!"#; diff --git a/src/project.rs b/src/project.rs new file mode 100644 index 00000000..0df00b9a --- /dev/null +++ b/src/project.rs @@ -0,0 +1,90 @@ +use glob::glob; +use serde::{Deserialize, Serialize}; +use std::error::Error; +use std::process::Command; + +/// Contains the structure of resulting rust-project.json file +/// and functions to build the data required to create the file +#[derive(Serialize, Deserialize)] +pub struct RustAnalyzerProject { + sysroot_src: String, + pub crates: Vec, +} + +#[derive(Serialize, Deserialize)] +pub struct Crate { + root_module: String, + edition: String, + deps: Vec, + cfg: Vec, +} + +impl RustAnalyzerProject { + pub fn new() -> RustAnalyzerProject { + RustAnalyzerProject { + sysroot_src: String::new(), + crates: Vec::new(), + } + } + + /// Write rust-project.json to disk + pub fn write_to_disk(&self) -> Result<(), std::io::Error> { + std::fs::write( + "./rust-project.json", + serde_json::to_vec(&self).expect("Failed to serialize to JSON"), + )?; + Ok(()) + } + + /// If path contains .rs extension, add a crate to `rust-project.json` + fn path_to_json(&mut self, path: String) { + if let Some((_, ext)) = path.split_once('.') { + if ext == "rs" { + self.crates.push(Crate { + root_module: path, + edition: "2021".to_string(), + deps: Vec::new(), + // This allows rust_analyzer to work inside #[test] blocks + cfg: vec!["test".to_string()], + }) + } + } + } + + /// Parse the exercises folder for .rs files, any matches will create + /// a new `crate` in rust-project.json which allows rust-analyzer to + /// treat it like a normal binary + pub fn exercies_to_json(&mut self) -> Result<(), Box> { + for e in glob("./exercises/**/*")? { + let path = e?.to_string_lossy().to_string(); + self.path_to_json(path); + } + Ok(()) + } + + /// Use `rustc` to determine the default toolchain + pub fn get_sysroot_src(&mut self) -> Result<(), Box> { + let toolchain = Command::new("rustc") + .arg("--print") + .arg("sysroot") + .output()? + .stdout; + + let toolchain = String::from_utf8_lossy(&toolchain); + let mut whitespace_iter = toolchain.split_whitespace(); + + let toolchain = whitespace_iter.next().unwrap_or(&toolchain); + + println!("Determined toolchain: {}\n", &toolchain); + + self.sysroot_src = (std::path::Path::new(&*toolchain) + .join("lib") + .join("rustlib") + .join("src") + .join("rust") + .join("library") + .to_string_lossy()) + .to_string(); + Ok(()) + } +} From 23403546d28c8ebfbb435856a738425c2a411389 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:01:03 +0000 Subject: [PATCH 293/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index a4b6bdf2..4dd7f7b5 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -175,6 +175,7 @@ authors.
pwygab

💻
Lucas Grigolon Varela

🖋
Bufo

🖋 +
Jack Clayton

💻 From e48f634f347fac37e0bec68d906265f7b6a22b8c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:01:04 +0000 Subject: [PATCH 294/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 00566c7e..a5975dc6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1227,6 +1227,15 @@ "contributions": [ "content" ] + }, + { + "login": "jackos", + "name": "Jack Clayton", + "avatar_url": "https://avatars.githubusercontent.com/u/77730378?v=4", + "profile": "http://rustnote.com", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From be3944072c3954b9570f17f9424f8d93d487d693 Mon Sep 17 00:00:00 2001 From: 0pling Date: Sun, 26 Jun 2022 10:27:18 +0800 Subject: [PATCH 295/476] docs: Add missing exercise to book chapter mapping --- exercises/README.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/exercises/README.md b/exercises/README.md index 73754db5..2ea29909 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -1,24 +1,24 @@ # Exercise to Book Chapter mapping -| Exercise | Book Chapter | -|------------------------|--------------| -| variables | §3.1 | -| functions | §3.3 | -| if | §3.5 | -| move_semantics | §4.1 | -| primitive_types | §4.3 | -| structs | §5.1 | -| enums | §6 | -| modules | §7 | -| collections | §8.1, §8.3 | -| strings | §8.2 | -| error_handling | §9 | -| generics | §10 | -| option | §10.1 | -| traits | §10.2 | -| tests | §11.1 | -| standard_library_types | §13.2 | -| threads | §16.1 | -| macros | §19.6 | -| clippy | n/a | -| conversions | n/a | +| Exercise | Book Chapter | +| ---------------------- | ------------------- | +| variables | §3.1 | +| functions | §3.3 | +| if | §3.5 | +| move_semantics | §4.1, §4.2 | +| primitive_types | §3.2, §4.3 | +| structs | §5.1, §5.3 | +| enums | §6, §18.3 | +| modules | §7 | +| collections | §8.1, §8.3 | +| strings | §8.2 | +| error_handling | §9 | +| generics | §10 | +| option | §10.1 | +| traits | §10.2 | +| tests | §11.1 | +| standard_library_types | §13.2, §15.1, §16.3 | +| threads | §16.1 | +| macros | §19.6 | +| clippy | n/a | +| conversions | n/a | From 6588d9be22b511c98520de4f4df0c3939aae610e Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 1 Jul 2022 16:48:34 +0200 Subject: [PATCH 296/476] chore: bump version --- CHANGELOG.md | 21 +++++++++++++++++++++ Cargo.toml | 2 +- src/main.rs | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc12506..095877b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ + +## 4.8.0 (2022-07-01) + +#### Features + +- Added a progress indicator for `rustlings watch`. +- The installation script now checks for Rustup being installed. +- Added a `rustlings lsp` command to enable `rust-analyzer`. + +#### Bug Fixes + +- **move_semantics5**: Replaced "in vogue" with "in scope" in hint. +- **if2**: Fixed a typo in the hint. +- **variables1**: Fixed an incorrect line reference in the hint. +- Fixed an out of bounds check in the installation Bash script. + +#### Housekeeping + +- Replaced the git.io URL with the fully qualified URL because of git.io's sunsetting. +- Removed the deprecated Rust GitPod extension. + ## 4.7.1 (2022-04-20) diff --git a/Cargo.toml b/Cargo.toml index e2a05aae..f7a1ffb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.7.1" +version = "4.8.0" authors = ["mokou ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 24ffbc5d..15c3095e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.7.1"; +const VERSION: &str = "4.8.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From a500ed2c3c6e8f8cd595260b54e18589279c5edb Mon Sep 17 00:00:00 2001 From: KatanaFluorescent <60199077+KatanaFluorescent@users.noreply.github.com> Date: Fri, 1 Jul 2022 16:49:36 +0200 Subject: [PATCH 297/476] change edition to 2021 in exercices.rs workaround for this issue https://github.com/rust-lang/rustlings/issues/1022 --- src/exercise.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exercise.rs b/src/exercise.rs index 6e49a9aa..4be3a2cc 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -121,7 +121,7 @@ impl Exercise { r#"[package] name = "{}" version = "0.0.1" -edition = "2018" +edition = "2021" [[bin]] name = "{}" path = "{}.rs""#, From df68d1a86e9967f4d05ff2dcc1e369bffe808e52 Mon Sep 17 00:00:00 2001 From: Drew Morris Date: Sat, 9 Jul 2022 16:50:57 -0600 Subject: [PATCH 298/476] chore: Update spacing in Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f7a1ffb8..e356a2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ console = "0.15" notify = "4.0" toml = "0.5" regex = "1.5" -serde= { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.81" home = "0.5.3" glob = "0.3.0" From c38d75481e62403cd5e7e446dd38148d77716e0d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:51:30 +0000 Subject: [PATCH 299/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 4dd7f7b5..fb42dcfe 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -176,6 +176,7 @@ authors.
Lucas Grigolon Varela

🖋
Bufo

🖋
Jack Clayton

💻 +
Konstantin

🖋 From c9e0d53ed2a6f8c96e4f41510e486e388971f755 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:51:31 +0000 Subject: [PATCH 300/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index a5975dc6..f1c0dc75 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1236,6 +1236,15 @@ "contributions": [ "code" ] + }, + { + "login": "klkl0808", + "name": "Konstantin", + "avatar_url": "https://avatars.githubusercontent.com/u/24694249?v=4", + "profile": "https://github.com/klkl0808", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From f73aec1a631051230761f864bb2108aea3cab70a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:53:38 +0000 Subject: [PATCH 301/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index fb42dcfe..a3262582 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -177,6 +177,7 @@ authors.
Bufo

🖋
Jack Clayton

💻
Konstantin

🖋 +
0pling

🖋 From 995ba213e279d47db20337a765c0643e2dd68259 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:53:39 +0000 Subject: [PATCH 302/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index f1c0dc75..3f8266d8 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1245,6 +1245,15 @@ "contributions": [ "content" ] + }, + { + "login": "0pling", + "name": "0pling", + "avatar_url": "https://avatars.githubusercontent.com/u/104090344?v=4", + "profile": "https://github.com/0pling", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 8835034bd25f692720d6571eaa34aa9dcf6855a8 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:58:18 +0000 Subject: [PATCH 303/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index a3262582..b67432cf 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -179,6 +179,9 @@ authors.
Konstantin

🖋
0pling

🖋 + +
KatanaFluorescent

💻 + From 440138af84875696f0b07562c29aba64350df05f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:58:19 +0000 Subject: [PATCH 304/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3f8266d8..5a258348 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1254,6 +1254,15 @@ "contributions": [ "content" ] + }, + { + "login": "KatanaFluorescent", + "name": "KatanaFluorescent", + "avatar_url": "https://avatars.githubusercontent.com/u/60199077?v=4", + "profile": "https://github.com/KatanaFluorescent", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 11618b65c07e2759e85d374e0f04d0a18e07a623 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:59:32 +0000 Subject: [PATCH 305/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index b67432cf..c2fe5d99 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -181,6 +181,7 @@ authors.
KatanaFluorescent

💻 +
Drew Morris

💻 From 1caa388e9287316b6c401ec88ad09cb23c63266e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 11 Jul 2022 09:59:33 +0000 Subject: [PATCH 306/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5a258348..06debdb4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1263,6 +1263,15 @@ "contributions": [ "code" ] + }, + { + "login": "Drew-Morris", + "name": "Drew Morris", + "avatar_url": "https://avatars.githubusercontent.com/u/95818166?v=4", + "profile": "https://github.com/Drew-Morris", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From ed0f278a8f116a1f69f20bba15485f019bfe2142 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 12:53:49 +0200 Subject: [PATCH 307/476] chore: remove mod.rs files and exercises feature --- Cargo.lock | 2 +- Cargo.toml | 5 +---- exercises/advanced_errors/mod.rs | 2 -- exercises/clippy/mod.rs | 2 -- exercises/collections/mod.rs | 4 ---- exercises/conversions/mod.rs | 5 ----- exercises/enums/mod.rs | 3 --- exercises/error_handling/mod.rs | 6 ------ exercises/functions/mod.rs | 5 ----- exercises/generics/mod.rs | 3 --- exercises/if/mod.rs | 2 -- exercises/intro/mod.rs | 2 -- exercises/macros/mod.rs | 4 ---- exercises/mod.rs | 26 ------------------------- exercises/modules/mod.rs | 3 --- exercises/move_semantics/mod.rs | 6 ------ exercises/option/mod.rs | 3 --- exercises/primitive_types/mod.rs | 6 ------ exercises/standard_library_types/mod.rs | 7 ------- exercises/strings/mod.rs | 2 -- exercises/structs/mod.rs | 3 --- exercises/tests/mod.rs | 3 --- exercises/threads/mod.rs | 1 - exercises/traits/mod.rs | 2 -- exercises/variables/mod.rs | 6 ------ src/lib.rs | 3 --- 26 files changed, 2 insertions(+), 114 deletions(-) delete mode 100644 exercises/advanced_errors/mod.rs delete mode 100644 exercises/clippy/mod.rs delete mode 100644 exercises/collections/mod.rs delete mode 100644 exercises/conversions/mod.rs delete mode 100644 exercises/enums/mod.rs delete mode 100644 exercises/error_handling/mod.rs delete mode 100644 exercises/functions/mod.rs delete mode 100644 exercises/generics/mod.rs delete mode 100644 exercises/if/mod.rs delete mode 100644 exercises/intro/mod.rs delete mode 100644 exercises/macros/mod.rs delete mode 100644 exercises/mod.rs delete mode 100644 exercises/modules/mod.rs delete mode 100644 exercises/move_semantics/mod.rs delete mode 100644 exercises/option/mod.rs delete mode 100644 exercises/primitive_types/mod.rs delete mode 100644 exercises/standard_library_types/mod.rs delete mode 100644 exercises/strings/mod.rs delete mode 100644 exercises/structs/mod.rs delete mode 100644 exercises/tests/mod.rs delete mode 100644 exercises/threads/mod.rs delete mode 100644 exercises/traits/mod.rs delete mode 100644 exercises/variables/mod.rs delete mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 6737d29c..df190ad8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.7.1" +version = "4.8.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index e356a2c2..8a3264d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustlings" version = "4.8.0" -authors = ["mokou ", "Carol (Nichols || Goulding) "] +authors = ["Liv ", "Carol (Nichols || Goulding) "] edition = "2021" [dependencies] @@ -24,6 +24,3 @@ path = "src/main.rs" assert_cmd = "0.11.0" predicates = "1.0.1" glob = "0.3.0" - -[features] -exercises = [] diff --git a/exercises/advanced_errors/mod.rs b/exercises/advanced_errors/mod.rs deleted file mode 100644 index e33fb80d..00000000 --- a/exercises/advanced_errors/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod advanced_errs1; -mod advanced_errs2; diff --git a/exercises/clippy/mod.rs b/exercises/clippy/mod.rs deleted file mode 100644 index 689dc95f..00000000 --- a/exercises/clippy/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod clippy1; -mod clippy2; diff --git a/exercises/collections/mod.rs b/exercises/collections/mod.rs deleted file mode 100644 index f46c1424..00000000 --- a/exercises/collections/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod hashmap1; -mod hashmap2; -mod vec1; -mod vec2; diff --git a/exercises/conversions/mod.rs b/exercises/conversions/mod.rs deleted file mode 100644 index 69f66ae4..00000000 --- a/exercises/conversions/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod as_ref_mut; -mod from_into; -mod from_str; -mod try_from_into; -mod using_as; diff --git a/exercises/enums/mod.rs b/exercises/enums/mod.rs deleted file mode 100644 index a23fd6e5..00000000 --- a/exercises/enums/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod enums1; -mod enums2; -mod enums3; diff --git a/exercises/error_handling/mod.rs b/exercises/error_handling/mod.rs deleted file mode 100644 index 539fa23d..00000000 --- a/exercises/error_handling/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod errors1; -mod errors2; -mod errors3; -mod errors4; -mod errors5; -mod errors6; diff --git a/exercises/functions/mod.rs b/exercises/functions/mod.rs deleted file mode 100644 index 445b6f58..00000000 --- a/exercises/functions/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod functions1; -mod functions2; -mod functions3; -mod functions4; -mod functions5; diff --git a/exercises/generics/mod.rs b/exercises/generics/mod.rs deleted file mode 100644 index 5b93555c..00000000 --- a/exercises/generics/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod generics1; -mod generics2; -mod generics3; diff --git a/exercises/if/mod.rs b/exercises/if/mod.rs deleted file mode 100644 index c5d02445..00000000 --- a/exercises/if/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod if1; -mod if2; diff --git a/exercises/intro/mod.rs b/exercises/intro/mod.rs deleted file mode 100644 index 445c47ab..00000000 --- a/exercises/intro/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod intro1; -mod intro2; diff --git a/exercises/macros/mod.rs b/exercises/macros/mod.rs deleted file mode 100644 index 9f65acf5..00000000 --- a/exercises/macros/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod macros1; -mod macros2; -mod macros3; -mod macros4; diff --git a/exercises/mod.rs b/exercises/mod.rs deleted file mode 100644 index 6a143b56..00000000 --- a/exercises/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -mod advanced_errors; -mod clippy; -mod collections; -mod conversions; -mod enums; -mod error_handling; -mod functions; -mod generics; -mod r#if; -mod intro; -mod macros; -mod modules; -mod move_semantics; -mod option; -mod primitive_types; -mod quiz1; -mod quiz2; -mod quiz3; -mod quiz4; -mod standard_library_types; -mod strings; -mod structs; -mod tests; -mod threads; -mod traits; -mod variables; diff --git a/exercises/modules/mod.rs b/exercises/modules/mod.rs deleted file mode 100644 index 35f96af5..00000000 --- a/exercises/modules/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod modules1; -mod modules2; -mod modules3; diff --git a/exercises/move_semantics/mod.rs b/exercises/move_semantics/mod.rs deleted file mode 100644 index e8eecf0a..00000000 --- a/exercises/move_semantics/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod move_semantics1; -mod move_semantics2; -mod move_semantics3; -mod move_semantics4; -mod move_semantics5; -mod move_semantics6; diff --git a/exercises/option/mod.rs b/exercises/option/mod.rs deleted file mode 100644 index b3cdb13d..00000000 --- a/exercises/option/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod option1; -mod option2; -mod option3; diff --git a/exercises/primitive_types/mod.rs b/exercises/primitive_types/mod.rs deleted file mode 100644 index 23355239..00000000 --- a/exercises/primitive_types/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod primitive_types1; -mod primitive_types2; -mod primitive_types3; -mod primitive_types4; -mod primitive_types5; -mod primitive_types6; diff --git a/exercises/standard_library_types/mod.rs b/exercises/standard_library_types/mod.rs deleted file mode 100644 index b03acb92..00000000 --- a/exercises/standard_library_types/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod arc1; -mod box1; -mod iterators1; -mod iterators2; -mod iterators3; -mod iterators4; -mod iterators5; diff --git a/exercises/strings/mod.rs b/exercises/strings/mod.rs deleted file mode 100644 index b1b460bc..00000000 --- a/exercises/strings/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod strings1; -mod strings2; diff --git a/exercises/structs/mod.rs b/exercises/structs/mod.rs deleted file mode 100644 index 214fed16..00000000 --- a/exercises/structs/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod structs1; -mod structs2; -mod structs3; diff --git a/exercises/tests/mod.rs b/exercises/tests/mod.rs deleted file mode 100644 index 489541be..00000000 --- a/exercises/tests/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod tests1; -mod tests2; -mod tests3; diff --git a/exercises/threads/mod.rs b/exercises/threads/mod.rs deleted file mode 100644 index 24d54007..00000000 --- a/exercises/threads/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod threads1; diff --git a/exercises/traits/mod.rs b/exercises/traits/mod.rs deleted file mode 100644 index 6f0a9c3f..00000000 --- a/exercises/traits/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod traits1; -mod traits2; diff --git a/exercises/variables/mod.rs b/exercises/variables/mod.rs deleted file mode 100644 index a25f477e..00000000 --- a/exercises/variables/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod variables1; -mod variables2; -mod variables3; -mod variables4; -mod variables5; -mod variables6; diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 82c1e7e4..00000000 --- a/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -#[cfg(feature = "exercises")] -#[path = "../exercises/mod.rs"] -mod exercises; From 0aee54a82b699d1e46d190b21d03101e8522b242 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 13:12:47 +0200 Subject: [PATCH 308/476] chore: unify hint language use --- info.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/info.toml b/info.toml index a9608e65..232908fc 100644 --- a/info.toml +++ b/info.toml @@ -21,7 +21,7 @@ name = "variables1" path = "exercises/variables/variables1.rs" mode = "compile" hint = """ -Hint: The declaration on line 8 is missing a keyword that is needed in Rust +The declaration on line 8 is missing a keyword that is needed in Rust to create a new variable binding.""" [[exercises]] @@ -360,14 +360,14 @@ name = "enums1" path = "exercises/enums/enums1.rs" mode = "compile" hint = """ -Hint: The declaration of the enumeration type has not been defined yet.""" +The declaration of the enumeration type has not been defined yet.""" [[exercises]] name = "enums2" path = "exercises/enums/enums2.rs" mode = "compile" hint = """ -Hint: you can create enumerations that have different variants with different types +You can create enumerations that have different variants with different types such as no data, anonymous structs, a single string, tuples, ...etc""" [[exercises]] @@ -536,7 +536,7 @@ name = "errors5" path = "exercises/error_handling/errors5.rs" mode = "compile" hint = """ -Hint: There are two different possible `Result` types produced within +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? @@ -980,7 +980,7 @@ or an Err with an error if the string is not valid. This is almost like the `from_into` exercise, but returning errors instead of falling back to a default value. -Hint: Look at the test cases to see which error variants to return. +Look at the test cases to see which error variants to return. Another hint: You can use the `map_err` method of `Result` with a function or a closure to wrap the error from `parse::`. @@ -998,7 +998,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 -Hint: Is there an implementation of `TryFrom` in the standard library that +Is there an implementation of `TryFrom` in the standard library that can both do the required integer conversion and check the range of the input? Another hint: Look at the test cases to see which error variants to return. From 0ded8a90c026bf5c6129d96956183c641ac1ad20 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 13:19:19 +0200 Subject: [PATCH 309/476] feat(intro1): add more hints --- exercises/intro/intro1.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs index 1c4582de..5d4becf3 100644 --- a/exercises/intro/intro1.rs +++ b/exercises/intro/intro1.rs @@ -4,6 +4,10 @@ // after you already figured it out. If you got everything working and feel // ready for the next exercise, remove the `I AM NOT DONE` comment below. // Execute the command `rustlings hint intro1` for a hint. +// +// If you're running this using `rustlings watch`: The exercise file will be reloaded +// when you change one of the lines below! Try adding a `println!` line, or try changing +// what it outputs in your terminal. Try removing a semicolon and see what happens! // I AM NOT DONE @@ -20,4 +24,7 @@ fn main() { println!("This exercise compiles successfully. The remaining exercises contain a compiler"); println!("or logic error. The central concept behind Rustlings is to fix these errors and"); println!("solve the exercises. Good luck!"); + println!(); + println!("The source for this exercise is in `exercises/intro/intro1.rs`. Have a look!"); + println!("Going forward, the source of the exercises will always be in the success/failure output."); } From 9ed4b0683edcf73ab0fbdcfe479a82898e6d5e42 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 13:20:18 +0200 Subject: [PATCH 310/476] fix(intro1): link to exercise file in hint --- info.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 232908fc..f3a52177 100644 --- a/info.toml +++ b/info.toml @@ -5,7 +5,8 @@ name = "intro1" path = "exercises/intro/intro1.rs" mode = "compile" hint = """ -Remove the I AM NOT DONE comment to move on to the next exercise.""" +Remove the I AM NOT DONE comment in the exercises/intro/intro1.rs file +to move on to the next exercise.""" [[exercises]] name = "intro2" From c3c21ad91fd66bcffedb85f542c1c830e1a7cdc0 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 13:35:16 +0200 Subject: [PATCH 311/476] fix(intro): clarify hint usage --- exercises/intro/intro1.rs | 2 +- exercises/intro/intro2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs index 5d4becf3..45c5acba 100644 --- a/exercises/intro/intro1.rs +++ b/exercises/intro/intro1.rs @@ -3,7 +3,7 @@ // We sometimes encourage you to keep trying things on a given exercise, even // after you already figured it out. If you got everything working and feel // ready for the next exercise, remove the `I AM NOT DONE` comment below. -// Execute the command `rustlings hint intro1` for a hint. +// Execute `rustlings hint intro1` or use the `hint` watch subcommand for a hint. // // If you're running this using `rustlings watch`: The exercise file will be reloaded // when you change one of the lines below! Try adding a `println!` line, or try changing diff --git a/exercises/intro/intro2.rs b/exercises/intro/intro2.rs index 97a073f0..efc1af20 100644 --- a/exercises/intro/intro2.rs +++ b/exercises/intro/intro2.rs @@ -1,6 +1,6 @@ // intro2.rs // Make the code print a greeting to the world. -// Execute `rustlings hint intro2` for a hint. +// Execute `rustlings hint intro2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 81edc4234fbe40eee34f83bbc2995c69f9e1e07c Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 13:43:41 +0200 Subject: [PATCH 312/476] fix(variables): reorder and redo hint texts --- exercises/variables/variables1.rs | 2 +- exercises/variables/variables2.rs | 6 +++--- exercises/variables/variables3.rs | 6 ++---- exercises/variables/variables4.rs | 6 ++++-- exercises/variables/variables5.rs | 2 +- exercises/variables/variables6.rs | 2 +- info.toml | 16 ++++++++-------- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index d1af8311..f4d182ac 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -1,6 +1,6 @@ // variables1.rs // Make me compile! -// Execute the command `rustlings hint variables1` if you want a hint :) +// Execute `rustlings hint variables1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..641aeb8e 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,13 +1,13 @@ // variables2.rs -// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) +// Execute `rustlings hint variables2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE fn main() { let x; if x == 10 { - println!("Ten!"); + println!("x is ten!"); } else { - println!("Not ten!"); + println!("x is not ten!"); } } diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 30ec48ff..819b1bc7 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,11 +1,9 @@ // variables3.rs -// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) +// Execute `rustlings hint variables3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE fn main() { - let x = 3; - println!("Number {}", x); - x = 5; // don't change this line + let x: i32; println!("Number {}", x); } diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..54491b0a 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,11 @@ // variables4.rs -// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) +// Execute `rustlings hint variables4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE fn main() { - let x: i32; + let x = 3; + println!("Number {}", x); + x = 5; // don't change this line println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 175eebb3..7042d6fa 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,5 +1,5 @@ // variables5.rs -// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) +// Execute `rustlings hint variables5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 98666914..a8520122 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,5 +1,5 @@ // variables6.rs -// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) +// Execute `rustlings hint variables6` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index f3a52177..c5f22f92 100644 --- a/info.toml +++ b/info.toml @@ -43,20 +43,20 @@ name = "variables3" path = "exercises/variables/variables3.rs" mode = "compile" hint = """ -In Rust, variable bindings are immutable by default. But here we're trying -to reassign a different value to x! There's a keyword we can use to make -a variable binding mutable instead.""" +Oops! In this exercise, we have a variable binding that we've created on +line 7, and we're trying to use it on line 8, but we haven't given it a +value. We can't print out something that isn't there; try giving x a value! +This is an error that can cause bugs that's very easy to make in any +programming language -- thankfully the Rust compiler has caught this for us!""" [[exercises]] name = "variables4" path = "exercises/variables/variables4.rs" mode = "compile" hint = """ -Oops! In this exercise, we have a variable binding that we've created on -line 7, and we're trying to use it on line 8, but we haven't given it a -value. We can't print out something that isn't there; try giving x a value! -This is an error that can cause bugs that's very easy to make in any -programming language -- thankfully the Rust compiler has caught this for us!""" +In Rust, variable bindings are immutable by default. But here we're trying +to reassign a different value to x! There's a keyword we can use to make +a variable binding mutable instead.""" [[exercises]] name = "variables5" From 60410cfd2ea4f819f633e3c69efe916d3f825536 Mon Sep 17 00:00:00 2001 From: gavin Date: Sun, 20 Feb 2022 10:53:51 +0530 Subject: [PATCH 313/476] fix(variables5): Add nudge for shadowing variable --- 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 7042d6fa..0e670d2a 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -6,6 +6,6 @@ fn main() { let number = "T-H-R-E-E"; // don't change this line println!("Spell a Number : {}", number); - number = 3; + number = 3; // don't rename this variable println!("Number plus two is : {}", number + 2); } From 9688609d0892757b2f0ce769367e7c5821e3f94c Mon Sep 17 00:00:00 2001 From: Cooper Gillan Date: Fri, 25 Feb 2022 02:33:45 +0000 Subject: [PATCH 314/476] chore: Update variables6.rs hint book link, wording While the included link for variables6 does navigate to the correct page, the header in the link itself does not actually exist so it only loads the top of the page. There is, however, some text about the difference between variables and constants in the "Constants" section, so reword the hint some and update the link. --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index c5f22f92..042172de 100644 --- a/info.toml +++ b/info.toml @@ -84,7 +84,7 @@ Constants are always immutable and they are declared with keyword 'const' rather than keyword 'let'. Constants types must also always be annotated. -Read more about constants under 'Differences Between Variables and Constants' in the book's section 'Variables and Mutability': +Read more about constants and the differences between variables and constants under 'Constants' in the book's section 'Variables and Mutability': https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#constants """ From b3ec8fe0223eda6ce31e72d464b6a56d71b2204f Mon Sep 17 00:00:00 2001 From: Cooper Gillan Date: Fri, 25 Feb 2022 02:35:43 +0000 Subject: [PATCH 315/476] chore: Tweak punctuation in variables6.rs hint While the meaning is still obvious as is, it makes a little more sense to use a colon here =) --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 042172de..d7906431 100644 --- a/info.toml +++ b/info.toml @@ -79,7 +79,7 @@ path = "exercises/variables/variables6.rs" mode = "compile" hint = """ We know about variables and mutability, but there is another important type of -variable available; constants. +variable available: constants. Constants are always immutable and they are declared with keyword 'const' rather than keyword 'let'. Constants types must also always be annotated. From 093a525450bd1d0092d91bb90969bffab2df55a9 Mon Sep 17 00:00:00 2001 From: mokou Date: Mon, 11 Jul 2022 14:00:12 +0200 Subject: [PATCH 316/476] fix(functions): clarify README wording --- exercises/functions/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/functions/README.md b/exercises/functions/README.md index 66547bd4..6662d0da 100644 --- a/exercises/functions/README.md +++ b/exercises/functions/README.md @@ -1,6 +1,7 @@ # Functions -Here, you'll learn how to write functions and how Rust's compiler can trace things way back. +Here, you'll learn how to write functions and how the Rust compiler can help you debug errors even +in more complex code. ## Further information From 742fb08e010725868ebdce41038461088d95a3d9 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 11:08:29 +0200 Subject: [PATCH 317/476] feat(functions): more small fixes --- exercises/functions/functions1.rs | 2 +- exercises/functions/functions2.rs | 2 +- exercises/functions/functions3.rs | 2 +- exercises/functions/functions4.rs | 5 ++++- exercises/functions/functions5.rs | 4 ++-- info.toml | 9 +++++++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..03d8af70 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,5 +1,5 @@ // functions1.rs -// Make me compile! Execute `rustlings hint functions1` for hints :) +// Execute `rustlings hint functions1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 5721a172..7d40a578 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,5 +1,5 @@ // functions2.rs -// Make me compile! Execute `rustlings hint functions2` for hints :) +// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index ed5f839f..3b9e585b 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,5 +1,5 @@ // functions3.rs -// Make me compile! Execute `rustlings hint functions3` for hints :) +// Execute `rustlings hint functions3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..65d5be4f 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -1,8 +1,11 @@ // functions4.rs -// Make me compile! Execute `rustlings hint functions4` for hints :) +// Execute `rustlings hint functions4` or use the `hint` watch subcommand for a hint. // This store is having a sale where if the price is an even number, you get // 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. +// (Don't worry about the function bodies themselves, we're only interested +// in the signatures for now. If anything, this is a good way to peek ahead +// to future exercises!) // I AM NOT DONE diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index d22aa6c8..5d762961 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,11 +1,11 @@ // functions5.rs -// Make me compile! Execute `rustlings hint functions5` for hints :) +// Execute `rustlings hint functions5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE fn main() { let answer = square(3); - println!("The answer is {}", answer); + println!("The square of 3 is {}", answer); } fn square(num: i32) -> i32 { diff --git a/info.toml b/info.toml index d7906431..84df9111 100644 --- a/info.toml +++ b/info.toml @@ -114,7 +114,9 @@ path = "exercises/functions/functions3.rs" mode = "compile" hint = """ This time, the function *declaration* is okay, but there's something wrong -with the place where we're calling the function.""" +with the place where we're calling the function. +As a reminder, you can freely play around with different solutions in Rustlings! +Watch mode will only jump to the next exercise if you remove the I AM NOT DONE comment.""" [[exercises]] name = "functions4" @@ -123,7 +125,10 @@ mode = "compile" hint = """ The error message points to line 14 and says it expects a type after the `->`. This is where the function's return type should be-- take a look at -the `is_even` function for an example!""" +the `is_even` function for an example! + +Also: Did you figure out that, technically, u32 would be the more fitting type +for the prices here, since they can't be negative? If so, kudos!""" [[exercises]] name = "functions5" From 4868d18ea315f15ad007086f218c8a1ee68a8eb4 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 11:10:08 +0200 Subject: [PATCH 318/476] feat(if): replace hints --- exercises/if/README.md | 2 +- exercises/if/if1.rs | 2 +- exercises/if/if2.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/if/README.md b/exercises/if/README.md index 528d9886..b52c3922 100644 --- a/exercises/if/README.md +++ b/exercises/if/README.md @@ -1,6 +1,6 @@ # If -`if`, the most basic type of control flow, is what you'll learn here. +`if`, the most basic (but still surprisingly versatile!) type of control flow, is what you'll learn here. ## Further information diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..587e03f8 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,4 +1,5 @@ // if1.rs +// Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -7,7 +8,6 @@ pub fn bigger(a: i32, b: i32) -> i32 { // Do not use: // - another function call // - additional variables - // Execute `rustlings hint if1` for hints } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 80effbdf..6fed6f81 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -2,7 +2,7 @@ // Step 1: Make me compile! // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! -// Execute the command `rustlings hint if2` if you want a hint :) +// Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 5812f1f27b0e3c2eed6e4606635bb810d0a5727e Mon Sep 17 00:00:00 2001 From: Adam Sherwood Date: Sun, 20 Feb 2022 16:15:56 +0100 Subject: [PATCH 319/476] fix(if2): Rename if2 exercise function to foo_if_fizz. The reasoning here is pretty straightforward: you don't say "Hungry, if eat." That doesn't make sense. We want to get "foo" back if given "fizz", so it seems this makes far more sense as "Eat, if hungry," or in this case, return `foo_if_fizz` is given. --- exercises/if/if2.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 6fed6f81..effddbb6 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -6,7 +6,7 @@ // I AM NOT DONE -pub fn fizz_if_foo(fizzish: &str) -> &str { +pub fn foo_if_fizz(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" } else { @@ -21,16 +21,16 @@ mod tests { #[test] fn foo_for_fizz() { - assert_eq!(fizz_if_foo("fizz"), "foo") + assert_eq!(foo_if_fizz("fizz"), "foo") } #[test] fn bar_for_fuzz() { - assert_eq!(fizz_if_foo("fuzz"), "bar") + assert_eq!(foo_if_fizz("fuzz"), "bar") } #[test] fn default_to_baz() { - assert_eq!(fizz_if_foo("literally anything"), "baz") + assert_eq!(foo_if_fizz("literally anything"), "baz") } } From 6020ec1fe21aa1763821940dcc7029b99fb9d00a Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 14:53:56 +0200 Subject: [PATCH 320/476] feat: reorder vec and primtypes before moving --- info.toml | 177 +++++++++++++++++++++++++++--------------------------- 1 file changed, 90 insertions(+), 87 deletions(-) diff --git a/info.toml b/info.toml index 84df9111..717ea95e 100644 --- a/info.toml +++ b/info.toml @@ -175,6 +175,96 @@ path = "exercises/quiz1.rs" mode = "test" hint = "No hints this time ;)" +# PRIMITIVE TYPES + +[[exercises]] +name = "primitive_types1" +path = "exercises/primitive_types/primitive_types1.rs" +mode = "compile" +hint = "No hints this time ;)" + +[[exercises]] +name = "primitive_types2" +path = "exercises/primitive_types/primitive_types2.rs" +mode = "compile" +hint = "No hints this time ;)" + +[[exercises]] +name = "primitive_types3" +path = "exercises/primitive_types/primitive_types3.rs" +mode = "compile" +hint = """ +There's a shorthand to initialize Arrays with a certain size that does not +require you to type in 100 items (but you certainly can if you want!). +For example, you can do: +let array = ["Are we there yet?"; 10]; + +Bonus: what are some other things you could have that would return true +for `a.len() >= 100`?""" + +[[exercises]] +name = "primitive_types4" +path = "exercises/primitive_types/primitive_types4.rs" +mode = "test" +hint = """ +Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book: +https://doc.rust-lang.org/book/ch04-03-slices.html +and use the starting and ending indices of the items in the Array +that you want to end up in the slice. + +If you're curious why the first argument of `assert_eq!` does not +have an ampersand for a reference since the second argument is a +reference, take a look at the coercion chapter of the nomicon: +https://doc.rust-lang.org/nomicon/coercions.html""" + +[[exercises]] +name = "primitive_types5" +path = "exercises/primitive_types/primitive_types5.rs" +mode = "compile" +hint = """ +Take a look at the Data Types -> The Tuple Type section of the book: +https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type +Particularly the part about destructuring (second to last example in the section). +You'll need to make a pattern to bind `name` and `age` to the appropriate parts +of the tuple. You can do it!!""" + +[[exercises]] +name = "primitive_types6" +path = "exercises/primitive_types/primitive_types6.rs" +mode = "test" +hint = """ +While you could use a destructuring `let` for the tuple here, try +indexing into it instead, as explained in the last example of the +Data Types -> The Tuple Type section of the book: +https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type +Now you have another tool in your toolbox!""" + +# VECS + +[[exercises]] +name = "vec1" +path = "exercises/collections/vec1.rs" +mode = "test" +hint = """ +In Rust, there are two ways to define a Vector. +1. One way is to use the `Vec::new()` function to create a new vector + and fill it with the `push()` method. +2. The second way, which is simpler is to use the `vec![]` macro and + define your elements inside the square brackets. +Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html +of the Rust book to learn more. +""" + +[[exercises]] +name = "vec2" +path = "exercises/collections/vec2.rs" +mode = "test" +hint = """ +Hint 1: `i` is each element from the Vec as they are being iterated. + Can you try multiplying this? +Hint 2: Check the suggestion from the compiler error ;) +""" + # MOVE SEMANTICS [[exercises]] @@ -258,69 +348,6 @@ Can you figure out how? Another hint: it has to do with the `&` character.""" -# PRIMITIVE TYPES - -[[exercises]] -name = "primitive_types1" -path = "exercises/primitive_types/primitive_types1.rs" -mode = "compile" -hint = "No hints this time ;)" - -[[exercises]] -name = "primitive_types2" -path = "exercises/primitive_types/primitive_types2.rs" -mode = "compile" -hint = "No hints this time ;)" - -[[exercises]] -name = "primitive_types3" -path = "exercises/primitive_types/primitive_types3.rs" -mode = "compile" -hint = """ -There's a shorthand to initialize Arrays with a certain size that does not -require you to type in 100 items (but you certainly can if you want!). -For example, you can do: -let array = ["Are we there yet?"; 10]; - -Bonus: what are some other things you could have that would return true -for `a.len() >= 100`?""" - -[[exercises]] -name = "primitive_types4" -path = "exercises/primitive_types/primitive_types4.rs" -mode = "test" -hint = """ -Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book: -https://doc.rust-lang.org/book/ch04-03-slices.html -and use the starting and ending indices of the items in the Array -that you want to end up in the slice. - -If you're curious why the first argument of `assert_eq!` does not -have an ampersand for a reference since the second argument is a -reference, take a look at the Deref coercions section of the book: -https://doc.rust-lang.org/book/ch15-02-deref.html""" - -[[exercises]] -name = "primitive_types5" -path = "exercises/primitive_types/primitive_types5.rs" -mode = "compile" -hint = """ -Take a look at the Data Types -> The Tuple Type section of the book: -https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type -Particularly the part about destructuring (second to last example in the section). -You'll need to make a pattern to bind `name` and `age` to the appropriate parts -of the tuple. You can do it!!""" - -[[exercises]] -name = "primitive_types6" -path = "exercises/primitive_types/primitive_types6.rs" -mode = "test" -hint = """ -While you could use a destructuring `let` for the tuple here, try -indexing into it instead, as explained in the last example of the -Data Types -> The Tuple Type section of the book: -https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type -Now you have another tool in your toolbox!""" # STRUCTS @@ -414,30 +441,6 @@ operator to bring these two in using only one line.""" # COLLECTIONS -[[exercises]] -name = "vec1" -path = "exercises/collections/vec1.rs" -mode = "test" -hint = """ -In Rust, there are two ways to define a Vector. -1. One way is to use the `Vec::new()` function to create a new vector - and fill it with the `push()` method. -2. The second way, which is simpler is to use the `vec![]` macro and - define your elements inside the square brackets. -Check this chapter: https://doc.rust-lang.org/stable/book/ch08-01-vectors.html -of the Rust book to learn more. -""" - -[[exercises]] -name = "vec2" -path = "exercises/collections/vec2.rs" -mode = "test" -hint = """ -Hint 1: `i` is each element from the Vec as they are being iterated. - Can you try multiplying this? -Hint 2: Check the suggestion from the compiler error ;) -""" - [[exercises]] name = "hashmap1" path = "exercises/collections/hashmap1.rs" From 7af12ba9aa45b57730b92cc00c3ddaa1527eb31f Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 14:54:12 +0200 Subject: [PATCH 321/476] feat(primitive_types): fixups --- exercises/primitive_types/primitive_types1.rs | 1 + exercises/primitive_types/primitive_types2.rs | 2 ++ exercises/primitive_types/primitive_types3.rs | 2 +- exercises/primitive_types/primitive_types4.rs | 2 +- exercises/primitive_types/primitive_types5.rs | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index 09121392..de0d08a6 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -4,6 +4,7 @@ // I AM NOT DONE +#[test] fn main() { // Booleans (`bool`) diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index 6576a4d5..8730baab 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -7,6 +7,8 @@ fn main() { // Characters (`char`) + // Note the _single_ quotes, these are different from the double quotes + // you've been seeing around. let my_first_initial = 'C'; if my_first_initial.is_alphabetic() { println!("Alphabetical!"); diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index aaa518be..fa7d019a 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -1,6 +1,6 @@ // primitive_types3.rs // Create an array with at least 100 elements in it where the ??? is. -// Execute `rustlings hint primitive_types3` for hints! +// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/primitive_types/primitive_types4.rs b/exercises/primitive_types/primitive_types4.rs index 10b553e9..71fa243c 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -1,6 +1,6 @@ // primitive_types4.rs // Get a slice out of Array a where the ??? is so that the test passes. -// Execute `rustlings hint primitive_types4` for hints!! +// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/primitive_types/primitive_types5.rs b/exercises/primitive_types/primitive_types5.rs index 680d8d23..4fd9141f 100644 --- a/exercises/primitive_types/primitive_types5.rs +++ b/exercises/primitive_types/primitive_types5.rs @@ -1,6 +1,6 @@ // primitive_types5.rs // Destructure the `cat` tuple so that the println will work. -// Execute `rustlings hint primitive_types5` for hints! +// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 8e1f617d3402cb05b05c6737f60fbbfe74da4d78 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:05:47 +0200 Subject: [PATCH 322/476] feat(vec): update vec exercises --- exercises/collections/vec1.rs | 2 +- exercises/collections/vec2.rs | 20 ++++++++++++++++++-- info.toml | 12 +++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index b144fb94..c26f5691 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -2,7 +2,7 @@ // Your task is to create a `Vec` which holds the exact same elements // as in the array `a`. // Make me compile and pass the test! -// Execute the command `rustlings hint vec1` if you need hints. +// Execute `rustlings hint vec1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index 6595e401..db37d1d6 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -4,8 +4,7 @@ // // Make me pass the test! // -// Execute the command `rustlings hint vec2` if you need -// hints. +// Execute `rustlings hint vec2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -13,12 +12,21 @@ fn vec_loop(mut v: Vec) -> Vec { for i in v.iter_mut() { // TODO: Fill this up so that each element in the Vec `v` is // multiplied by 2. + ??? } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. v } +fn vec_map(v: &Vec) -> Vec { + v.iter().map(|num| { + // TODO: Do the same thing as above - but instead of mutating the + // Vec, you can just return the new number! + ??? + }).collect() +} + #[cfg(test)] mod tests { use super::*; @@ -30,4 +38,12 @@ mod tests { assert_eq!(ans, v.iter().map(|x| x * 2).collect::>()); } + + #[test] + fn test_vec_map() { + let v: Vec = (1..).filter(|x| x % 2 == 0).take(5).collect(); + let ans = vec_map(&v); + + assert_eq!(ans, v.iter().map(|x| x * 2).collect::>()); + } } diff --git a/info.toml b/info.toml index 717ea95e..af4861c2 100644 --- a/info.toml +++ b/info.toml @@ -260,9 +260,15 @@ name = "vec2" path = "exercises/collections/vec2.rs" mode = "test" hint = """ -Hint 1: `i` is each element from the Vec as they are being iterated. - Can you try multiplying this? -Hint 2: Check the suggestion from the compiler error ;) +Hint 1: `i` is each element from the Vec as they are being iterated. Can you try +multiplying this? + +Hint 2: For the first function, there's a way to directly access the numbers stored +in the Vec, using the * dereference operator. You can both access and write to the +number that way. + +After you've completed both functions, decide for yourself which approach you like +better. What do you think is the more commonly used pattern under Rust developers? """ # MOVE SEMANTICS From 2f7fd513041c7c6275552650881a79b9120aaacf Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:16:25 +0200 Subject: [PATCH 323/476] feat: move vec exercises into their own folder --- exercises/collections/README.md | 24 +++++-------------- exercises/vecs/README.md | 15 ++++++++++++ .../{collections/vec1.rs => vecs/vecs1.rs} | 4 ++-- .../{collections/vec2.rs => vecs/vecs2.rs} | 4 ++-- info.toml | 8 +++---- 5 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 exercises/vecs/README.md rename exercises/{collections/vec1.rs => vecs/vecs1.rs} (84%) rename exercises/{collections/vec2.rs => vecs/vecs2.rs} (92%) diff --git a/exercises/collections/README.md b/exercises/collections/README.md index b6d62acb..30471cf9 100644 --- a/exercises/collections/README.md +++ b/exercises/collections/README.md @@ -1,23 +1,11 @@ -# Collections +# Hashmaps +A *hash map* allows you to associate a value with a particular key. +You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), +[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. -Rust’s standard library includes a number of very useful data -structures called collections. Most other data types represent one -specific value, but collections can contain multiple values. Unlike -the built-in array and tuple types, the data these collections point -to is stored on the heap, which means the amount of data does not need -to be known at compile time and can grow or shrink as the program -runs. - -This exercise will get you familiar with two fundamental data -structures that are used very often in Rust programs: - -* A *vector* allows you to store a variable number of values next to - each other. -* A *hash map* allows you to associate a value with a particular key. - You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), - [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. +This is the other data structure that we've been talking about before, when +talking about Vecs. ## 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) diff --git a/exercises/vecs/README.md b/exercises/vecs/README.md new file mode 100644 index 00000000..ebe90bf3 --- /dev/null +++ b/exercises/vecs/README.md @@ -0,0 +1,15 @@ +# Vectors + +Vectors are one of the most-used Rust data structures. In other programming +languages, they'd simply be called Arrays, but since Rust operates on a +bit of a lower level, an array in Rust is stored on the stack (meaning it +can't grow or shrink, and the size needs to be known at compile time), +and a Vector is stored in the heap (where these restrictions do not apply). + +Vectors are a bit of a later chapter in the book, but we think that they're +useful enough to talk about them a bit earlier. We shall be talking about +the other useful data structure, hash maps, later. + +## Further information + +- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html) diff --git a/exercises/collections/vec1.rs b/exercises/vecs/vecs1.rs similarity index 84% rename from exercises/collections/vec1.rs rename to exercises/vecs/vecs1.rs index c26f5691..4e8c4cbb 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/vecs/vecs1.rs @@ -1,8 +1,8 @@ -// vec1.rs +// vecs1.rs // Your task is to create a `Vec` which holds the exact same elements // as in the array `a`. // Make me compile and pass the test! -// Execute `rustlings hint vec1` or use the `hint` watch subcommand for a hint. +// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/collections/vec2.rs b/exercises/vecs/vecs2.rs similarity index 92% rename from exercises/collections/vec2.rs rename to exercises/vecs/vecs2.rs index db37d1d6..5bea09a2 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/vecs/vecs2.rs @@ -1,10 +1,10 @@ -// vec2.rs +// vecs2.rs // A Vec of even numbers is given. Your task is to complete the loop // so that each number in the Vec is multiplied by 2. // // Make me pass the test! // -// Execute `rustlings hint vec2` or use the `hint` watch subcommand for a hint. +// Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index af4861c2..1e941e13 100644 --- a/info.toml +++ b/info.toml @@ -242,8 +242,8 @@ Now you have another tool in your toolbox!""" # VECS [[exercises]] -name = "vec1" -path = "exercises/collections/vec1.rs" +name = "vecs1" +path = "exercises/vecs/vecs1.rs" mode = "test" hint = """ In Rust, there are two ways to define a Vector. @@ -256,8 +256,8 @@ of the Rust book to learn more. """ [[exercises]] -name = "vec2" -path = "exercises/collections/vec2.rs" +name = "vecs2" +path = "exercises/vecs/vecs2.rs" mode = "test" hint = """ Hint 1: `i` is each element from the Vec as they are being iterated. Can you try From 3c4c9c54c98142f114018bbbe4d0d96d63646a5b Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:18:05 +0200 Subject: [PATCH 324/476] feat: remove collections to hashmaps --- exercises/{collections => hashmaps}/README.md | 0 .../{collections/hashmap1.rs => hashmaps/hashmaps1.rs} | 4 ++-- .../{collections/hashmap2.rs => hashmaps/hashmaps2.rs} | 4 ++-- info.toml | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) rename exercises/{collections => hashmaps}/README.md (100%) rename exercises/{collections/hashmap1.rs => hashmaps/hashmaps1.rs} (93%) rename exercises/{collections/hashmap2.rs => hashmaps/hashmaps2.rs} (96%) diff --git a/exercises/collections/README.md b/exercises/hashmaps/README.md similarity index 100% rename from exercises/collections/README.md rename to exercises/hashmaps/README.md diff --git a/exercises/collections/hashmap1.rs b/exercises/hashmaps/hashmaps1.rs similarity index 93% rename from exercises/collections/hashmap1.rs rename to exercises/hashmaps/hashmaps1.rs index 64b5a7f3..26178b0d 100644 --- a/exercises/collections/hashmap1.rs +++ b/exercises/hashmaps/hashmaps1.rs @@ -1,4 +1,4 @@ -// hashmap1.rs +// hashmaps1.rs // A basket of fruits in the form of a hash map needs to be defined. // The key represents the name of the fruit and the value represents // how many of that particular fruit is in the basket. You have to put @@ -8,7 +8,7 @@ // // Make me compile and pass the tests! // -// Execute the command `rustlings hint hashmap1` if you need +// Execute the command `rustlings hint hashmaps1` if you need // hints. // I AM NOT DONE diff --git a/exercises/collections/hashmap2.rs b/exercises/hashmaps/hashmaps2.rs similarity index 96% rename from exercises/collections/hashmap2.rs rename to exercises/hashmaps/hashmaps2.rs index 0abe19ab..1afb8303 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/hashmaps/hashmaps2.rs @@ -1,4 +1,4 @@ -// hashmap2.rs +// hashmaps2.rs // A basket of fruits in the form of a hash map is given. The key // represents the name of the fruit and the value represents how many @@ -9,7 +9,7 @@ // // Make me pass the tests! // -// Execute the command `rustlings hint hashmap2` if you need +// Execute the command `rustlings hint hashmaps2` if you need // hints. // I AM NOT DONE diff --git a/info.toml b/info.toml index 1e941e13..c6231203 100644 --- a/info.toml +++ b/info.toml @@ -445,11 +445,11 @@ UNIX_EPOCH and SystemTime are declared in the std::time module. Add a use statem 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 +# HASHMAPS [[exercises]] -name = "hashmap1" -path = "exercises/collections/hashmap1.rs" +name = "hashmaps1" +path = "exercises/hashmaps/hashmaps1.rs" mode = "test" hint = """ Hint 1: Take a look at the return type of the function to figure out @@ -459,8 +459,8 @@ Hint 2: Number of fruits should be at least 5. And you have to put """ [[exercises]] -name = "hashmap2" -path = "exercises/collections/hashmap2.rs" +name = "hashmaps2" +path = "exercises/hashmaps/hashmaps2.rs" mode = "test" hint = """ Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this. From 7452d0d60395a9b0247abb3b307ab3437c1f8622 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:22:01 +0200 Subject: [PATCH 325/476] fix(primitive_types): clean up --- exercises/primitive_types/primitive_types1.rs | 1 - exercises/primitive_types/primitive_types6.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index de0d08a6..09121392 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -4,7 +4,6 @@ // I AM NOT DONE -#[test] fn main() { // Booleans (`bool`) diff --git a/exercises/primitive_types/primitive_types6.rs b/exercises/primitive_types/primitive_types6.rs index b8c9b82b..ddf8b423 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -1,7 +1,7 @@ // primitive_types6.rs // Use a tuple index to access the second element of `numbers`. // You can put the expression for the second element where ??? is so that the test passes. -// Execute `rustlings hint primitive_types6` for hints! +// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From bb0cf92b8b6f0a9db4be92ff5ffc4c507f2847ba Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:25:31 +0200 Subject: [PATCH 326/476] feat(move_semantics): clarify some hints --- exercises/move_semantics/move_semantics1.rs | 2 +- exercises/move_semantics/move_semantics2.rs | 2 +- info.toml | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index e2f5876d..aac6dfc3 100644 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -1,5 +1,5 @@ // move_semantics1.rs -// Make me compile! Execute `rustlings hint move_semantics1` for hints :) +// Execute `rustlings hint move_semantics1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index 888dc529..64870850 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -1,6 +1,6 @@ // move_semantics2.rs // Make me compile without changing line 13 or moving line 10! -// Execute `rustlings hint move_semantics2` for hints :) +// Execute `rustlings hint move_semantics2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index c6231203..a7c46eb6 100644 --- a/info.toml +++ b/info.toml @@ -280,18 +280,21 @@ mode = "compile" hint = """ So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 13, right? The fix for this is going to be adding one keyword, and the addition is NOT on line 13 -where the error is.""" +where the error is. + +Also: Try accessing `vec0` after having called `fill_vec()`. See what happens!""" [[exercises]] name = "move_semantics2" path = "exercises/move_semantics/move_semantics2.rs" mode = "compile" hint = """ -So `vec0` is being *moved* into the function `fill_vec` when we call it on -line 10, which means it gets dropped at the end of `fill_vec`, which means we -can't use `vec0` again on line 13 (or anywhere else in `main` after the -`fill_vec` call for that matter). We could fix this in a few ways, try them -all! +So, `vec0` is passed into the `fill_vec` function as an argument. In Rust, +when an argument is passed to a function and it's not explicitly returned, +you can't use the original variable anymore. We call this "moving" a variable. +Variables that are moved into a function (or block scope) and aren't explicitly +returned get "dropped" at the end of that function. This is also what happens here. +There's a few ways to fix this, try them all if you want: 1. Make another, separate version of the data that's in `vec0` and pass that to `fill_vec` instead. 2. Make `fill_vec` borrow its argument instead of taking ownership of it, From 16ff57bbffe0ab86d9ef880d45486d6625cc9223 Mon Sep 17 00:00:00 2001 From: exdx Date: Tue, 12 Jul 2022 15:26:55 +0200 Subject: [PATCH 327/476] fix(move_semantics2): clarify referencing --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index a7c46eb6..899d4c18 100644 --- a/info.toml +++ b/info.toml @@ -300,7 +300,7 @@ There's a few ways to fix this, try them all if you want: 2. Make `fill_vec` borrow its argument instead of taking ownership of it, and then copy the data within the function in order to return an owned `Vec` -3. Make `fill_vec` *mutably* borrow its argument (which will need to be +3. Make `fill_vec` *mutably* borrow a reference to its argument (which will need to be mutable), modify it directly, then not return anything. Then you can get rid of `vec1` entirely -- note that this will change what gets printed by the first `println!`""" From 2e62505143a726c610a60cc8f11fbb4b0449ba8f Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 12 Jul 2022 15:43:26 +0200 Subject: [PATCH 328/476] feat(move_semantics): finish updating comments --- exercises/move_semantics/move_semantics3.rs | 2 +- exercises/move_semantics/move_semantics4.rs | 8 ++++---- exercises/move_semantics/move_semantics5.rs | 2 +- exercises/move_semantics/move_semantics6.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/move_semantics/move_semantics3.rs b/exercises/move_semantics/move_semantics3.rs index 43fef74f..eaa30e33 100644 --- a/exercises/move_semantics/move_semantics3.rs +++ b/exercises/move_semantics/move_semantics3.rs @@ -1,7 +1,7 @@ // move_semantics3.rs // Make me compile without adding new lines-- just changing existing lines! // (no lines with multiple semicolons necessary!) -// Execute `rustlings hint move_semantics3` for hints :) +// Execute `rustlings hint move_semantics3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index 2a23c710..99834ec3 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -1,8 +1,8 @@ // move_semantics4.rs -// Refactor this code so that instead of having `vec0` and creating the vector -// in `fn main`, we create it within `fn fill_vec` and transfer the -// freshly created vector from fill_vec to its caller. -// Execute `rustlings hint move_semantics4` for hints! +// Refactor this code so that instead of passing `vec0` into the `fill_vec` function, +// the Vector gets created in the function itself and passed back to the main +// function. +// Execute `rustlings hint move_semantics4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index c4704f9e..36eae127 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -1,7 +1,7 @@ // move_semantics5.rs // Make me compile only by reordering the lines in `main()`, but without // adding, changing or removing any of them. -// Execute `rustlings hint move_semantics5` for hints :) +// Execute `rustlings hint move_semantics5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/move_semantics/move_semantics6.rs b/exercises/move_semantics/move_semantics6.rs index 457e7ae7..eb52a848 100644 --- a/exercises/move_semantics/move_semantics6.rs +++ b/exercises/move_semantics/move_semantics6.rs @@ -1,6 +1,6 @@ // move_semantics6.rs -// Make me compile! `rustlings hint move_semantics6` for hints -// You can't change anything except adding or removing references +// Execute `rustlings hint move_semantics6` or use the `hint` watch subcommand for a hint. +// You can't change anything except adding or removing references. // I AM NOT DONE From 19bec503998c3c5618254015bada63b44a713f0e Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 11:59:29 +0200 Subject: [PATCH 329/476] feat(structs1): convert structs to use i32 types --- exercises/structs/structs1.rs | 11 +++++++---- info.toml | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 6d0b2f49..1632b685 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -1,5 +1,6 @@ // structs1.rs // Address all the TODOs to make the tests pass! +// Execute `rustlings hint structs1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -21,8 +22,9 @@ mod tests { // TODO: Instantiate a classic c struct! // let green = - assert_eq!(green.name, "green"); - assert_eq!(green.hex, "#00FF00"); + assert_eq!(green.red, 0); + assert_eq!(green.green, 255); + assert_eq!(green.blue, 0); } #[test] @@ -30,8 +32,9 @@ mod tests { // TODO: Instantiate a tuple struct! // let green = - assert_eq!(green.0, "green"); - assert_eq!(green.1, "#00FF00"); + assert_eq!(green.0, 0); + assert_eq!(green.1, 255); + assert_eq!(green.2, 0); } #[test] diff --git a/info.toml b/info.toml index 899d4c18..2dc49a38 100644 --- a/info.toml +++ b/info.toml @@ -357,7 +357,6 @@ Can you figure out how? Another hint: it has to do with the `&` character.""" - # STRUCTS [[exercises]] From 4dffa0d10df61748b0098ad4428848e6f3e90bff Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:00:46 +0200 Subject: [PATCH 330/476] fix(structs1): rename to unit-like struct --- exercises/structs/structs1.rs | 10 +++++----- info.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 1632b685..0d91c469 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -11,7 +11,7 @@ struct ColorClassicStruct { struct ColorTupleStruct(/* TODO: Something goes here */); #[derive(Debug)] -struct UnitStruct; +struct UnitLikeStruct; #[cfg(test)] mod tests { @@ -39,10 +39,10 @@ mod tests { #[test] fn unit_structs() { - // TODO: Instantiate a unit struct! - // let unit_struct = - let message = format!("{:?}s are fun!", unit_struct); + // TODO: Instantiate a unit-like struct! + // let unit_like_struct = + let message = format!("{:?}s are fun!", unit_like_struct); - assert_eq!(message, "UnitStructs are fun!"); + assert_eq!(message, "UnitLikeStructs are fun!"); } } diff --git a/info.toml b/info.toml index 2dc49a38..357a25c6 100644 --- a/info.toml +++ b/info.toml @@ -367,7 +367,7 @@ hint = """ Rust has more than one type of struct. Three actually, all variants are used to package related data together. There are normal (or classic) structs. These are named collections of related data stored in fields. Tuple structs are basically just named tuples. -Finally, Unit structs. These don't have any fields and are useful for generics. +Finally, Unit-like structs. These don't have any fields and are useful for generics. In this exercise you need to complete and implement one of each kind. Read more about structs in The Book: https://doc.rust-lang.org/book/ch05-01-defining-structs.html""" From 4531c21bf1b54ff5fa8cc796584043b826cf78e8 Mon Sep 17 00:00:00 2001 From: camperdue42 Date: Fri, 31 Dec 2021 01:05:34 -0500 Subject: [PATCH 331/476] fix(structs3): Add panic! statement into structs3 closes #685 --- 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 e84f2ebc..e5666e21 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -16,7 +16,7 @@ struct Package { impl Package { fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package { if weight_in_grams <= 0 { - // panic statement goes here... + panic!("Can not ship a weightless package.") } else { Package { sender_country, From 886d599c96ad0725cee05c50cf4ea9718fc02746 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:04:54 +0200 Subject: [PATCH 332/476] fix(structs): add hint comments --- exercises/structs/structs2.rs | 1 + exercises/structs/structs3.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/structs/structs2.rs b/exercises/structs/structs2.rs index f9c6427d..32e311fa 100644 --- a/exercises/structs/structs2.rs +++ b/exercises/structs/structs2.rs @@ -1,5 +1,6 @@ // structs2.rs // Address all the TODOs to make the tests pass! +// Execute `rustlings hint structs2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index e5666e21..0b3615f4 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -2,7 +2,7 @@ // Structs contain data, but can also have logic. In this exercise we have // defined the Package struct and we want to test some logic attached to it. // Make the code compile and the tests pass! -// If you have issues execute `rustlings hint structs3` +// Execute `rustlings hint structs3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 8fe02d33a93cd5af8bb9f7a69df8c7f20918465e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:06:03 +0000 Subject: [PATCH 333/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index c2fe5d99..f5af8cbb 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -182,6 +182,7 @@ authors.
KatanaFluorescent

💻
Drew Morris

💻 +
camperdue42

🖋 From 62578269eb739c534efb8225d85169bba9951fa1 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:06:04 +0000 Subject: [PATCH 334/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 06debdb4..941ee530 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1272,6 +1272,15 @@ "contributions": [ "code" ] + }, + { + "login": "camperdue42", + "name": "camperdue42", + "avatar_url": "https://avatars.githubusercontent.com/u/43047763?v=4", + "profile": "https://github.com/camperdue42", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d0e8efd19ee9a4a7fe9a62ee76bc035371321c09 Mon Sep 17 00:00:00 2001 From: Ryosuke YASUOKA Date: Sun, 9 Jan 2022 19:30:31 +0900 Subject: [PATCH 335/476] feat(enums3): Add hint --- info.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 357a25c6..dc176ed0 100644 --- a/info.toml +++ b/info.toml @@ -415,7 +415,11 @@ such as no data, anonymous structs, a single string, tuples, ...etc""" name = "enums3" path = "exercises/enums/enums3.rs" mode = "test" -hint = "No hints this time ;)" +hint = """ +As a first step, you can define enums to compile this code without errors. +and then create a match expression in `process()`. +Note that you need to deconstruct some message variants +in the match expression to get value in the variant.""" # MODULES From c6bc97adc10aecbf6a1ba5ff5c7beda1f421a098 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:11:38 +0200 Subject: [PATCH 336/476] feat(enums3): add hint comment, remove enums1 hint --- exercises/enums/enums1.rs | 2 +- exercises/enums/enums2.rs | 2 +- exercises/enums/enums3.rs | 1 + info.toml | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/enums/enums1.rs b/exercises/enums/enums1.rs index a2223d33..511ba740 100644 --- a/exercises/enums/enums1.rs +++ b/exercises/enums/enums1.rs @@ -1,5 +1,5 @@ // enums1.rs -// Make me compile! Execute `rustlings hint enums1` for hints! +// No hints this time! ;) // I AM NOT DONE diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index ec32d952..18479f87 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -1,5 +1,5 @@ // enums2.rs -// Make me compile! Execute `rustlings hint enums2` for hints! +// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index 178b40c4..55acf6bc 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -1,5 +1,6 @@ // enums3.rs // Address all the TODOs to make the tests pass! +// Execute `rustlings hint enums3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index dc176ed0..b1e448c9 100644 --- a/info.toml +++ b/info.toml @@ -400,8 +400,7 @@ Have a look in The Book, to find out more about method implementations: https:// name = "enums1" path = "exercises/enums/enums1.rs" mode = "compile" -hint = """ -The declaration of the enumeration type has not been defined yet.""" +hint = "No hints this time ;)" [[exercises]] name = "enums2" From 0ddb9970761a645df4c3d6365a142c6333465190 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:12:32 +0000 Subject: [PATCH 337/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index f5af8cbb..4c1cba01 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -183,6 +183,7 @@ authors.
KatanaFluorescent

💻
Drew Morris

💻
camperdue42

🖋 +
YsuOS

🖋 From c92de1f8a6f7187b02d51cd119e1e301a06981bd Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:12:33 +0000 Subject: [PATCH 338/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 941ee530..eceb7666 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1281,6 +1281,15 @@ "contributions": [ "content" ] + }, + { + "login": "YsuOS", + "name": "YsuOS", + "avatar_url": "https://avatars.githubusercontent.com/u/30138661?v=4", + "profile": "https://github.com/YsuOS", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From f5e4c16eed0c9e86398284bb6732981c3cc074c8 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:18:21 +0200 Subject: [PATCH 339/476] feat(strings): move before modules --- exercises/strings/strings1.rs | 2 +- exercises/strings/strings2.rs | 2 +- info.toml | 46 +++++++++++++++++------------------ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/exercises/strings/strings1.rs b/exercises/strings/strings1.rs index 80902444..0de86a1d 100644 --- a/exercises/strings/strings1.rs +++ b/exercises/strings/strings1.rs @@ -1,6 +1,6 @@ // strings1.rs // Make me compile without changing the function signature! -// Execute `rustlings hint strings1` for hints ;) +// Execute `rustlings hint strings1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/strings/strings2.rs b/exercises/strings/strings2.rs index 5a2ce74a..0c48ec95 100644 --- a/exercises/strings/strings2.rs +++ b/exercises/strings/strings2.rs @@ -1,6 +1,6 @@ // strings2.rs // Make me compile without changing the function signature! -// Execute `rustlings hint strings2` for hints :) +// Execute `rustlings hint strings2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index b1e448c9..8174fc8f 100644 --- a/info.toml +++ b/info.toml @@ -420,6 +420,29 @@ and then create a match expression in `process()`. Note that you need to deconstruct some message variants in the match expression to get value in the variant.""" +# STRINGS + +[[exercises]] +name = "strings1" +path = "exercises/strings/strings1.rs" +mode = "compile" +hint = """ +The `current_favorite_color` function is currently returning a string slice with the `'static` +lifetime. We know this because the data of the string lives in our code itself -- it doesn't +come from a file or user input or another program -- so it will live as long as our program +lives. But it is still a string slice. There's one way to create a `String` by converting a +string slice covered in the Strings chapter of the book, and another way that uses the `From` +trait.""" + +[[exercises]] +name = "strings2" +path = "exercises/strings/strings2.rs" +mode = "compile" +hint = """ +Yes, it would be really easy to fix this by just changing the value bound to `word` to be a +string slice instead of a `String`, wouldn't it?? There is a way to add one character to line +9, though, that will coerce the `String` into a string slice.""" + # MODULES [[exercises]] @@ -472,29 +495,6 @@ Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this. Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value """ -# STRINGS - -[[exercises]] -name = "strings1" -path = "exercises/strings/strings1.rs" -mode = "compile" -hint = """ -The `current_favorite_color` function is currently returning a string slice with the `'static` -lifetime. We know this because the data of the string lives in our code itself -- it doesn't -come from a file or user input or another program -- so it will live as long as our program -lives. But it is still a string slice. There's one way to create a `String` by converting a -string slice covered in the Strings chapter of the book, and another way that uses the `From` -trait.""" - -[[exercises]] -name = "strings2" -path = "exercises/strings/strings2.rs" -mode = "compile" -hint = """ -Yes, it would be really easy to fix this by just changing the value bound to `word` to be a -string slice instead of a `String`, wouldn't it?? There is a way to add one character to line -9, though, that will coerce the `String` into a string slice.""" - # TEST 2 [[exercises]] From c1ed6b10fe0725846fef8328b328159b6302fe3b Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:31:28 +0200 Subject: [PATCH 340/476] feat(strings): add strings3 --- exercises/strings/strings3.rs | 41 +++++++++++++++++++++++++++++++++++ info.toml | 11 ++++++++++ 2 files changed, 52 insertions(+) create mode 100644 exercises/strings/strings3.rs diff --git a/exercises/strings/strings3.rs b/exercises/strings/strings3.rs new file mode 100644 index 00000000..bb0a259e --- /dev/null +++ b/exercises/strings/strings3.rs @@ -0,0 +1,41 @@ +// strings3.rs +// Execute `rustlings hint strings3` or use the `hint` watch subcommand for a hint. + +fn trim_me(input: &str) -> String { + // TODO: Remove whitespace from the end of a string! + ??? +} + +fn compose_me(input: &str) -> String { + // TODO: Add " world!" to the string! There's multiple ways to do this! + ??? +} + +fn replace_me(input: &str) -> String { + // TODO: Replace "cars" in the string with "balloons"! + ??? +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn trim_a_string() { + assert_eq!(trim_me("Hello! "), "Hello!"); + assert_eq!(trim_me(" What's up!"), "What's up!"); + assert_eq!(trim_me(" Hola! "), "Hola!"); + } + + #[test] + fn compose_a_string() { + assert_eq!(compose_me("Hello"), "Hello world!"); + assert_eq!(compose_me("Goodbye"), "Goodbye world!"); + } + + #[test] + fn replace_a_string() { + assert_eq!(replace_me("I think cars are cool"), "I think balloons are cool"); + assert_eq!(replace_me("I love to look at cars"), "I love to look at balloons"); + } +} diff --git a/info.toml b/info.toml index 8174fc8f..c54672b3 100644 --- a/info.toml +++ b/info.toml @@ -443,6 +443,17 @@ Yes, it would be really easy to fix this by just changing the value bound to `wo string slice instead of a `String`, wouldn't it?? There is a way to add one character to line 9, though, that will coerce the `String` into a string slice.""" +[[exercises]] +name = "strings3" +path = "exercises/strings/strings3.rs" +mode = "test" +hint = """ +There's tons of useful standard library functions for strings. Let's try and use some of +them! + +For the compose_me method: You can either use the `format!` macro, or convert the string +slice into an owned string, which you can then freely extend.""" + # MODULES [[exercises]] From fe54d0f85b3170ba950bab8be9756c9dbf0098fd Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:35:49 +0200 Subject: [PATCH 341/476] fix(modules): adjust hint comments --- exercises/modules/modules1.rs | 2 +- exercises/modules/modules2.rs | 3 +-- exercises/modules/modules3.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 1a2bd0dd..8dd0e402 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -1,5 +1,5 @@ // modules1.rs -// Make me compile! Execute `rustlings hint modules1` for hints :) +// Execute `rustlings hint modules1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index 87f0c458..c30a3897 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -1,12 +1,11 @@ // modules2.rs // You can bring module paths into scopes and provide new names for them with the // 'use' and 'as' keywords. Fix these 'use' statements to make the code compile. -// Make me compile! Execute `rustlings hint modules2` for hints :) +// Execute `rustlings hint modules2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE mod delicious_snacks { - // TODO: Fix these use statements use self::fruits::PEAR as ??? use self::veggies::CUCUMBER as ??? diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs index 8eed77df..35e07990 100644 --- a/exercises/modules/modules3.rs +++ b/exercises/modules/modules3.rs @@ -3,7 +3,7 @@ // 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 :) +// Execute `rustlings hint modules3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 1e54bc61e81a81b0647325f724690b376de50a2a Mon Sep 17 00:00:00 2001 From: Sateesh Basavaraju Date: Fri, 4 Jun 2021 16:09:12 +0530 Subject: [PATCH 342/476] feat: Add hashmap3 exercise. --- exercises/hashmaps/hashmaps3.rs | 88 +++++++++++++++++++++++++++++++++ info.toml | 12 +++++ 2 files changed, 100 insertions(+) create mode 100644 exercises/hashmaps/hashmaps3.rs diff --git a/exercises/hashmaps/hashmaps3.rs b/exercises/hashmaps/hashmaps3.rs new file mode 100644 index 00000000..60293f2e --- /dev/null +++ b/exercises/hashmaps/hashmaps3.rs @@ -0,0 +1,88 @@ +// hashmaps3.rs + +// A list of scores (one per line) of a soccer match is given. Each line +// is of the form : +// ,,, +// Example: England,France,4,2 (England scored 4 goals, France 2). + +// You have to build a scores table containing the name of the team, goals +// the team scored, and goals the team conceded. One approach to build +// the scores table is to use a Hashmap. The solution is partially +// written to use a Hashmap, complete it to pass the test. + +// Make me pass the tests! + +// Execute the command `rustlings hint hashmap3` if you need +// hints. + +// I AM NOT DONE + +use std::collections::HashMap; + +// A structure to store team name and its goal details. +struct Team { + name: String, + goals_scored: u8, + goals_conceded: u8, +} + +fn build_scores_table(results: String) -> HashMap { + // The name of the team is the key and its associated struct is the value. + let mut scores: HashMap = HashMap::new(); + + for r in results.lines() { + let v: Vec<&str> = r.split(',').collect(); + let team_1_name = v[0].to_string(); + let team_1_score: u8 = v[2].parse().unwrap(); + let team_2_name = v[1].to_string(); + let team_2_score: u8 = v[3].parse().unwrap(); + // TODO: Populate the scores table with details extracted from the + // current line. Keep in mind that goals scored by team_1 + // will be number of goals conceded from team_2, and similarly + // goals scored by team_2 will be the number of goals conceded by + // team_1. + } + scores +} + +#[cfg(test)] +mod tests { + use super::*; + + fn get_results() -> String { + let results = "".to_string() + + "England,France,4,2\n" + + "France,Italy,3,1\n" + + "Poland,Spain,2,0\n" + + "Germany,England,2,1\n"; + results + } + + #[test] + fn build_scores() { + let scores = build_scores_table(get_results()); + + let mut keys: Vec<&String> = scores.keys().collect(); + keys.sort(); + assert_eq!( + keys, + vec!["England", "France", "Germany", "Italy", "Poland", "Spain"] + ); + } + + #[test] + fn validate_team_score_1() { + let scores = build_scores_table(get_results()); + let team = scores.get("England").unwrap(); + assert_eq!(team.goals_scored, 5); + assert_eq!(team.goals_conceded, 4); + } + + #[test] + fn validate_team_score_2() { + let scores = build_scores_table(get_results()); + let team = scores.get("Spain").unwrap(); + assert_eq!(team.goals_scored, 0); + assert_eq!(team.goals_conceded, 2); + } +} diff --git a/info.toml b/info.toml index c54672b3..ec2d8172 100644 --- a/info.toml +++ b/info.toml @@ -506,6 +506,18 @@ Use the `entry()` and `or_insert()` methods of `HashMap` to achieve this. Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value """ +[[exercises]] +name = "hashmaps3" +path = "exercises/hashmaps/hashmaps3.rs" +mode = "test" +hint = """ +Hint 1: Use the `entry()` and `or_insert()` methods of `HashMap` to insert entries corresponding to each team in the scores table. +Learn more at https://doc.rust-lang.org/stable/book/ch08-03-hash-maps.html#only-inserting-a-value-if-the-key-has-no-value +Hint 2: If there is already an entry for a given key, the value returned by `entry()` can be updated based on the existing value. +Learn more at https://doc.rust-lang.org/book/ch08-03-hash-maps.html#updating-a-value-based-on-the-old-value +""" + + # TEST 2 [[exercises]] From ab8572e15bf6765471490281ba2a1c8f88275e40 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 12:58:28 +0200 Subject: [PATCH 343/476] fix(hashmaps): adjust hint comments --- exercises/hashmaps/hashmaps1.rs | 3 +-- exercises/hashmaps/hashmaps2.rs | 3 +-- exercises/hashmaps/hashmaps3.rs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exercises/hashmaps/hashmaps1.rs b/exercises/hashmaps/hashmaps1.rs index 26178b0d..fd8dd2f8 100644 --- a/exercises/hashmaps/hashmaps1.rs +++ b/exercises/hashmaps/hashmaps1.rs @@ -8,8 +8,7 @@ // // Make me compile and pass the tests! // -// Execute the command `rustlings hint hashmaps1` if you need -// hints. +// Execute `rustlings hint hashmaps1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/hashmaps/hashmaps2.rs b/exercises/hashmaps/hashmaps2.rs index 1afb8303..454b3e1d 100644 --- a/exercises/hashmaps/hashmaps2.rs +++ b/exercises/hashmaps/hashmaps2.rs @@ -9,8 +9,7 @@ // // Make me pass the tests! // -// Execute the command `rustlings hint hashmaps2` if you need -// hints. +// Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/hashmaps/hashmaps3.rs b/exercises/hashmaps/hashmaps3.rs index 60293f2e..18dd44c9 100644 --- a/exercises/hashmaps/hashmaps3.rs +++ b/exercises/hashmaps/hashmaps3.rs @@ -12,8 +12,7 @@ // Make me pass the tests! -// Execute the command `rustlings hint hashmap3` if you need -// hints. +// Execute `rustlings hint hashmaps3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From f443f4e7b31467b29271aab477c63eb64aba1be3 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 13:01:40 +0200 Subject: [PATCH 344/476] feat: move quiz2 to be strings4 --- exercises/strings/strings4.rs | 29 +++++++++++++++++++++++++++++ info.toml | 11 ++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 exercises/strings/strings4.rs diff --git a/exercises/strings/strings4.rs b/exercises/strings/strings4.rs new file mode 100644 index 00000000..c410b562 --- /dev/null +++ b/exercises/strings/strings4.rs @@ -0,0 +1,29 @@ +// strings4.rs + +// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your +// task is to call one of these two functions on each value depending on what +// you think each value is. That is, add either `string_slice` or `string` +// before the parentheses on each line. If you're right, it will compile! +// No hints this time! + +// I AM NOT DONE + +fn string_slice(arg: &str) { + println!("{}", arg); +} +fn string(arg: String) { + println!("{}", arg); +} + +fn main() { + ???("blue"); + ???("red".to_string()); + ???(String::from("hi")); + ???("rust is fun!".to_owned()); + ???("nice weather".into()); + ???(format!("Interpolation {}", "Station")); + ???(&String::from("abc")[0..1]); + ???(" hello there ".trim()); + ???("Happy Monday!".to_string().replace("Mon", "Tues")); + ???("mY sHiFt KeY iS sTiCkY".to_lowercase()); +} diff --git a/info.toml b/info.toml index ec2d8172..0f7d9253 100644 --- a/info.toml +++ b/info.toml @@ -167,7 +167,7 @@ For that first compiler error, it's important in Rust that each conditional block returns the same type! To get the tests passing, you will need a couple conditions checking different input values.""" -# TEST 1 +# QUIZ 1 [[exercises]] name = "quiz1" @@ -454,6 +454,12 @@ them! For the compose_me method: You can either use the `format!` macro, or convert the string slice into an owned string, which you can then freely extend.""" +[[exercises]] +name = "strings4" +path = "exercises/strings/strings4.rs" +mode = "compile" +hint = "No hints this time ;)" + # MODULES [[exercises]] @@ -517,8 +523,7 @@ Hint 2: If there is already an entry for a given key, the value returned by `ent Learn more at https://doc.rust-lang.org/book/ch08-03-hash-maps.html#updating-a-value-based-on-the-old-value """ - -# TEST 2 +# QUIZ 2 [[exercises]] name = "quiz2" From c64b340622a59f60b0b056ed849557bc4872a535 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 13:16:32 +0200 Subject: [PATCH 345/476] feat: rework quiz2 --- exercises/quiz2.rs | 73 ++++++++++++++++++++++++++++++++-------------- info.toml | 2 +- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index de0dce95..d2211c7c 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -1,30 +1,59 @@ // quiz2.rs // This is a quiz for the following sections: // - Strings +// - Vecs +// - Move semantics +// - Modules +// - Enums -// Ok, here are a bunch of values-- some are `String`s, some are `&str`s. Your -// task is to call one of these two functions on each value depending on what -// you think each value is. That is, add either `string_slice` or `string` -// before the parentheses on each line. If you're right, it will compile! +// Let's build a little machine in form of a function. +// As input, we're going to give a list of strings and commands. These commands +// determine what action is going to be applied to the string. It can either be: +// - Uppercase the string +// - Trim the string +// - Append "bar" to the string a specified amount of times +// The exact form of this will be: +// - The input is going to be a Vector of a 2-length tuple, +// the first element is the string, the second one is the command. +// - The output element is going to be a Vector of strings. -// I AM NOT DONE - -fn string_slice(arg: &str) { - println!("{}", arg); -} -fn string(arg: String) { - println!("{}", arg); +pub enum Command { + Uppercase, + Trim, + Append(usize), } -fn main() { - ???("blue"); - ???("red".to_string()); - ???(String::from("hi")); - ???("rust is fun!".to_owned()); - ???("nice weather".into()); - ???(format!("Interpolation {}", "Station")); - ???(&String::from("abc")[0..1]); - ???(" hello there ".trim()); - ???("Happy Monday!".to_string().replace("Mon", "Tues")); - ???("mY sHiFt KeY iS sTiCkY".to_lowercase()); +mod my_module { + use super::Command; + + // TODO: Complete the function signature! + pub fn transformer(input: ???) -> ??? { + // TODO: Complete the output declaration! + let mut output: ??? = vec![]; + for (string, command) in input.iter() { + // TODO: Complete the function body. You can do it! + } + output + } +} + +#[cfg(test)] +mod tests { + // TODO: What to we have to import to have `transformer` in scope? + use ???; + use super::Command; + + #[test] + fn it_works() { + let output = transformer(vec![ + ("hello".into(), Command::Uppercase), + (" all roads lead to rome! ".into(), Command::Trim), + ("foo".into(), Command::Append(1)), + ("bar".into(), Command::Append(5)), + ]); + assert_eq!(output[0], "HELLO"); + assert_eq!(output[1], "all roads lead to rome!"); + assert_eq!(output[2], "foobar"); + assert_eq!(output[3], "barbarbarbarbarbar"); + } } diff --git a/info.toml b/info.toml index 0f7d9253..0a94f7de 100644 --- a/info.toml +++ b/info.toml @@ -528,7 +528,7 @@ Learn more at https://doc.rust-lang.org/book/ch08-03-hash-maps.html#updating-a-v [[exercises]] name = "quiz2" path = "exercises/quiz2.rs" -mode = "compile" +mode = "test" hint = "No hints this time ;)" # ERROR HANDLING From 472d7944f95e41d8fa9f78ac2870a3827afdc544 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 17:30:04 +0200 Subject: [PATCH 346/476] fix(quiz2): add hint comment --- exercises/quiz2.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index d2211c7c..5d3ccc03 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -16,6 +16,7 @@ // - The input is going to be a Vector of a 2-length tuple, // the first element is the string, the second one is the command. // - The output element is going to be a Vector of strings. +// Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint. pub enum Command { Uppercase, From b644558c19dd1f0319204f50c1c162562edb79b1 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 17:34:50 +0200 Subject: [PATCH 347/476] fix: rename option to options --- exercises/{option => options}/README.md | 2 +- .../option1.rs => options/options1.rs} | 4 +- .../option2.rs => options/options2.rs} | 2 +- .../option3.rs => options/options3.rs} | 2 +- info.toml | 84 +++++++++---------- 5 files changed, 47 insertions(+), 47 deletions(-) rename exercises/{option => options}/README.md (99%) rename exercises/{option/option1.rs => options/options1.rs} (81%) rename exercises/{option/option2.rs => options/options2.rs} (98%) rename exercises/{option/option3.rs => options/options3.rs} (96%) diff --git a/exercises/option/README.md b/exercises/options/README.md similarity index 99% rename from exercises/option/README.md rename to exercises/options/README.md index 89c00289..6140a167 100644 --- a/exercises/option/README.md +++ b/exercises/options/README.md @@ -1,4 +1,4 @@ -# Option +# Options Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. Option types are very common in Rust code, as they have a number of uses: diff --git a/exercises/option/option1.rs b/exercises/options/options1.rs similarity index 81% rename from exercises/option/option1.rs rename to exercises/options/options1.rs index 17cf4f60..9d96817b 100644 --- a/exercises/option/option1.rs +++ b/exercises/options/options1.rs @@ -1,5 +1,5 @@ -// option1.rs -// Make me compile! Execute `rustlings hint option1` for hints +// options1.rs +// Execute `rustlings hint options1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/option/option2.rs b/exercises/options/options2.rs similarity index 98% rename from exercises/option/option2.rs rename to exercises/options/options2.rs index c6b83ece..a1c21d3e 100644 --- a/exercises/option/option2.rs +++ b/exercises/options/options2.rs @@ -1,4 +1,4 @@ -// option2.rs +// options2.rs // Make me compile! Execute `rustlings hint option2` for hints // I AM NOT DONE diff --git a/exercises/option/option3.rs b/exercises/options/options3.rs similarity index 96% rename from exercises/option/option3.rs rename to exercises/options/options3.rs index 045d2acb..4cba4ad0 100644 --- a/exercises/option/option3.rs +++ b/exercises/options/options3.rs @@ -1,4 +1,4 @@ -// option3.rs +// options3.rs // Make me compile! Execute `rustlings hint option3` for hints // I AM NOT DONE diff --git a/info.toml b/info.toml index 0a94f7de..6bcf2786 100644 --- a/info.toml +++ b/info.toml @@ -531,6 +531,48 @@ path = "exercises/quiz2.rs" mode = "test" hint = "No hints this time ;)" +# OPTIONS + +[[exercises]] +name = "options1" +path = "exercises/options/options1.rs" +mode = "compile" +hint = """ +Hint 1: Check out some functions of Option: +is_some +is_none +unwrap + +and: +pattern matching + +Hint 2: There are no sensible defaults for the value of an Array; the values need to be filled before use. +""" + +[[exercises]] +name = "options2" +path = "exercises/options/options2.rs" +mode = "compile" +hint = """ +check out: +https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html +https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html + +Remember that Options can be stacked in if let and while let. +For example: Some(Some(variable)) = variable2 +Also see Option::flatten +""" + +[[exercises]] +name = "options3" +path = "exercises/options/options3.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""" + # ERROR HANDLING [[exercises]] @@ -661,48 +703,6 @@ ReportCard struct generic, but also the correct property - you will need to chan of the struct slightly too...you can do it! """ -# OPTIONS - -[[exercises]] -name = "option1" -path = "exercises/option/option1.rs" -mode = "compile" -hint = """ -Hint 1: Check out some functions of Option: -is_some -is_none -unwrap - -and: -pattern matching - -Hint 2: There are no sensible defaults for the value of an Array; the values need to be filled before use. -""" - -[[exercises]] -name = "option2" -path = "exercises/option/option2.rs" -mode = "compile" -hint = """ -check out: -https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html -https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html - -Remember that Options can be stacked in if let and while let. -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""" - # TRAITS [[exercises]] From 06e4fd376586709082664a304f0394244d4ab6bd Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 17:53:27 +0200 Subject: [PATCH 348/476] feat(options1): rewrite to remove array stuff --- exercises/options/options1.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index 9d96817b..038fb48e 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -8,16 +8,30 @@ fn print_number(maybe_number: Option) { println!("printing: {}", maybe_number.unwrap()); } -fn main() { - print_number(13); - print_number(99); +// This function returns how much icecream there is left in the fridge. +// If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them +// all, so there'll be no more left :( +// TODO: Return an Option! +fn maybe_icecream(time_of_day: u16) -> Option { + // We use the 24-hour system here, so 10PM is a value of 22 + ??? +} - let mut numbers: [Option; 5]; - for iter in 0..5 { - let number_to_add: u16 = { - ((iter * 1235) + 2) / (4 * 16) - }; +#[cfg(test)] +mod tests { + use super::*; - numbers[iter as usize] = number_to_add; + #[test] + fn check_icecream() { + assert_eq!(maybe_icecream(10), Some(5)); + assert_eq!(maybe_icecream(23), None); + assert_eq!(maybe_icecream(22), None); + } + + #[test] + fn raw_value() { + // TODO: Fix this test. How do you get at the value contained in the Option? + let icecreams = maybe_icecream(12); + assert_eq!(icecreams, 5); } } From b71feed82464f476611765e8621b32e615b5dddc Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 17:53:42 +0200 Subject: [PATCH 349/476] feat(options): add hint comments --- exercises/options/options2.rs | 2 +- exercises/options/options3.rs | 2 +- info.toml | 15 ++++----------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/exercises/options/options2.rs b/exercises/options/options2.rs index a1c21d3e..75b66a37 100644 --- a/exercises/options/options2.rs +++ b/exercises/options/options2.rs @@ -1,5 +1,5 @@ // options2.rs -// Make me compile! Execute `rustlings hint option2` for hints +// Execute `rustlings hint options2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/options/options3.rs b/exercises/options/options3.rs index 4cba4ad0..3f995c52 100644 --- a/exercises/options/options3.rs +++ b/exercises/options/options3.rs @@ -1,5 +1,5 @@ // options3.rs -// Make me compile! Execute `rustlings hint option3` for hints +// Execute `rustlings hint options3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index 6bcf2786..b13ed45e 100644 --- a/info.toml +++ b/info.toml @@ -536,18 +536,11 @@ hint = "No hints this time ;)" [[exercises]] name = "options1" path = "exercises/options/options1.rs" -mode = "compile" +mode = "test" hint = """ -Hint 1: Check out some functions of Option: -is_some -is_none -unwrap - -and: -pattern matching - -Hint 2: There are no sensible defaults for the value of an Array; the values need to be filled before use. -""" +Options can have a Some value, with an inner value, or a None value, without an inner value. +There's multiple ways to get at the inner value, you can use unwrap, or pattern match. Unwrapping +is the easiest, but how do you do it safely so that it doesn't panic in your face later?""" [[exercises]] name = "options2" From 582320aded8a9369f8b5a959419f04ea6d3f5b04 Mon Sep 17 00:00:00 2001 From: Steven nguyen Date: Tue, 8 Feb 2022 17:46:22 -0600 Subject: [PATCH 350/476] chore(errors1): use `is_empty()` instead of `len() > 0` more idiomatic according to clippy --- exercises/error_handling/errors1.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index c417fb26..1a2a8577 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -8,11 +8,11 @@ // I AM NOT DONE pub fn generate_nametag_text(name: String) -> Option { - if name.len() > 0 { - Some(format!("Hi! My name is {}", name)) - } else { + if name.is_empty() { // Empty names aren't allowed. None + } else { + Some(format!("Hi! My name is {}", name)) } } From 5e1ca4b99577578a1c92d71eeba49d88f60dcedc Mon Sep 17 00:00:00 2001 From: Noah Cairns Date: Wed, 15 Jun 2022 09:40:30 -0400 Subject: [PATCH 351/476] fix(errors5): improve exercise instructions --- exercises/error_handling/errors5.rs | 16 +++++++++++++--- info.toml | 19 +++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 365a8691..9d5ee4b7 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -1,7 +1,17 @@ // errors5.rs -// This program uses a completed version of the code from errors4. -// It won't compile right now! Why? +// This program uses an altered version of the code from errors4. + +// 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. + +// In short, this particular use case for boxes is for when you want to own a value and you care only that it is a +// type which implements a particular trait. To do so, The Box is declared as of type Box where Trait is the trait +// the compiler looks for on any value used in that context. For this exercise, that context is the potential errors +// which can be returned in a Result. + +// What can we use to describe both errors? In other words, is there a trait which both errors implement? + // Execute `rustlings hint errors5` for hints! // I AM NOT DONE @@ -11,7 +21,7 @@ use std::fmt; use std::num::ParseIntError; // TODO: update the return type of `main()` to make this compile. -fn main() -> Result<(), ParseIntError> { +fn main() -> Result<(), Box> { let pretend_user_input = "42"; let x: i64 = pretend_user_input.parse()?; println!("output={:?}", PositiveNonzeroInteger::new(x)?); diff --git a/info.toml b/info.toml index b13ed45e..97c174f5 100644 --- a/info.toml +++ b/info.toml @@ -619,22 +619,17 @@ name = "errors5" path = "exercises/error_handling/errors5.rs" mode = "compile" 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? +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? + +Under the hood, the `?` operator calls `From::from` on the error value to convert it to a boxed +trait object, a `Box`. This boxed trait object is polymorphic, and since all +errors implement the `error:Error` trait, we can capture lots of different errors in one "Box" +object. -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. 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. - Read more about boxing errors: https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html From c34e2adcbb261f71fbd013d61257457dd84bd849 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:02:33 +0200 Subject: [PATCH 352/476] feat(errors): Improve comments and hints --- exercises/error_handling/errors1.rs | 2 +- exercises/error_handling/errors2.rs | 3 ++- exercises/error_handling/errors3.rs | 2 +- exercises/error_handling/errors4.rs | 3 ++- exercises/error_handling/errors5.rs | 2 +- exercises/error_handling/errors6.rs | 6 +++++- info.toml | 5 ++++- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 1a2a8577..bcee9723 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -3,7 +3,7 @@ // you pass it an empty string. It'd be nicer if it explained what the problem // was, instead of just sometimes returning `None`. Thankfully, Rust has a similar // construct to `Option` that can be used to express error conditions. Let's use it! -// Execute `rustlings hint errors1` for hints! +// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors2.rs b/exercises/error_handling/errors2.rs index aad3a93f..1cd8fc66 100644 --- a/exercises/error_handling/errors2.rs +++ b/exercises/error_handling/errors2.rs @@ -14,7 +14,8 @@ // and add. // There are at least two ways to implement this that are both correct-- but -// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways. +// one is a lot shorter! +// Execute `rustlings hint errors2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors3.rs b/exercises/error_handling/errors3.rs index 460ac5c4..a2d2d190 100644 --- a/exercises/error_handling/errors3.rs +++ b/exercises/error_handling/errors3.rs @@ -2,7 +2,7 @@ // This is a program that is trying to use a completed version of the // `total_cost` function from the previous exercise. It's not working though! // Why not? What should we do to fix it? -// Execute `rustlings hint errors3` for hints! +// Execute `rustlings hint errors3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors4.rs b/exercises/error_handling/errors4.rs index 0685c374..0efe8ccd 100644 --- a/exercises/error_handling/errors4.rs +++ b/exercises/error_handling/errors4.rs @@ -1,5 +1,5 @@ // errors4.rs -// Make this test pass! Execute `rustlings hint errors4` for hints :) +// Execute `rustlings hint errors4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -14,6 +14,7 @@ enum CreationError { impl PositiveNonzeroInteger { fn new(value: i64) -> Result { + // Hmm...? Why is this only returning an Ok value? Ok(PositiveNonzeroInteger(value as u64)) } } diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 9d5ee4b7..67411c58 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -12,7 +12,7 @@ // What can we use to describe both errors? In other words, is there a trait which both errors implement? -// Execute `rustlings hint errors5` for hints! +// Execute `rustlings hint errors5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index 847a049a..1306fb03 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -6,7 +6,7 @@ // 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 :) +// Execute `rustlings hint errors6` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -20,7 +20,11 @@ enum ParsePosNonzeroError { } impl ParsePosNonzeroError { + fn from_creation(err: CreationError) -> ParsePosNonzeroError { + ParsePosNonzeroError::Creation(err) + } // TODO: add another error conversion function here. + // fn from_parseint... } fn parse_pos_nonzero(s: &str) diff --git a/info.toml b/info.toml index 97c174f5..cb49a973 100644 --- a/info.toml +++ b/info.toml @@ -603,7 +603,10 @@ name = "errors3" path = "exercises/error_handling/errors3.rs" mode = "compile" hint = """ -If other functions can return a `Result`, why shouldn't `main`?""" +If other functions can return a `Result`, why shouldn't `main`? It's a fairly common +convention to return something like Result<(), ErrorType> from your main function. +The unit (`()`) type is there because nothing is really needed in terms of positive +results.""" [[exercises]] name = "errors4" From 5d02f6e5163f799b727e8baa9c12a5219da6941b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:03:14 +0000 Subject: [PATCH 353/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 4c1cba01..9952c333 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -184,6 +184,7 @@ authors.
Drew Morris

💻
camperdue42

🖋
YsuOS

🖋 +
Steven Nguyen

🖋 From 34c8833d066f54331292c80ed4d8e048e4048716 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:03:15 +0000 Subject: [PATCH 354/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index eceb7666..a364a852 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1290,6 +1290,15 @@ "contributions": [ "content" ] + }, + { + "login": "icecream17", + "name": "Steven Nguyen", + "avatar_url": "https://avatars.githubusercontent.com/u/58114641?v=4", + "profile": "https://lichess.org/@/StevenEmily", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From b2c82d9018367e4237f4658dd3b49369cc406036 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:03:57 +0000 Subject: [PATCH 355/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 9952c333..720db577 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -185,6 +185,7 @@ authors.
camperdue42

🖋
YsuOS

🖋
Steven Nguyen

🖋 +
nacairns1

🖋 From 537abe273a20adac617e4a81a6fb45fec86bc2c5 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:03:58 +0000 Subject: [PATCH 356/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index a364a852..e2c0bc2a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1299,6 +1299,15 @@ "contributions": [ "content" ] + }, + { + "login": "nacairns1", + "name": "nacairns1", + "avatar_url": "https://avatars.githubusercontent.com/u/94420090?v=4", + "profile": "https://noahcairns.dev", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d61f79595a8929c118e76f78c6ec26ca49219062 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:11:05 +0200 Subject: [PATCH 357/476] feat(generics): add hint comments --- exercises/generics/generics1.rs | 2 +- exercises/generics/generics2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index f93e64a0..4c34ae47 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -1,7 +1,7 @@ // This shopping list program isn't compiling! // Use your knowledge of generics to fix it. -// Execute `rustlings hint generics1` for hints! +// Execute `rustlings hint generics1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 1501529c..aedbd55c 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -1,7 +1,7 @@ // 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! +// Execute `rustlings hint generics2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 5979d408a9d3f174bf748b82d1a031a25b548af6 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:11:18 +0200 Subject: [PATCH 358/476] feat: move generics3 to be quiz3 --- exercises/generics/generics3.rs | 58 --------------------------------- exercises/quiz3.rs | 58 +++++++++++++++++++++++++-------- info.toml | 31 ++++++------------ 3 files changed, 55 insertions(+), 92 deletions(-) delete mode 100644 exercises/generics/generics3.rs diff --git a/exercises/generics/generics3.rs b/exercises/generics/generics3.rs deleted file mode 100644 index 64dd9bc1..00000000 --- a/exercises/generics/generics3.rs +++ /dev/null @@ -1,58 +0,0 @@ -// An imaginary magical school has a new report card generation system written in Rust! -// Currently the system only supports creating report cards where the student's grade -// is represented numerically (e.g. 1.0 -> 5.5). -// However, the school also issues alphabetical grades (A+ -> F-) and needs -// to be able to print both types of report card! - -// Make the necessary code changes in the struct ReportCard and the impl block -// to support alphabetical report cards. Change the Grade in the second test to "A+" -// to show that your changes allow alphabetical grades. - -// Execute 'rustlings hint generics3' for hints! - -// I AM NOT DONE - -pub struct ReportCard { - pub grade: f32, - pub student_name: String, - pub student_age: u8, -} - -impl ReportCard { - pub fn print(&self) -> String { - format!("{} ({}) - achieved a grade of {}", - &self.student_name, &self.student_age, &self.grade) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn generate_numeric_report_card() { - let report_card = ReportCard { - grade: 2.1, - student_name: "Tom Wriggle".to_string(), - student_age: 12, - }; - assert_eq!( - report_card.print(), - "Tom Wriggle (12) - achieved a grade of 2.1" - ); - } - - #[test] - fn generate_alphabetic_report_card() { - // TODO: Make sure to change the grade here after you finish the exercise. - let report_card = ReportCard { - grade: 2.1, - student_name: "Gary Plotter".to_string(), - student_age: 11, - }; - assert_eq!( - report_card.print(), - "Gary Plotter (11) - achieved a grade of A+" - ); - } -} diff --git a/exercises/quiz3.rs b/exercises/quiz3.rs index fae0eedb..15dc4699 100644 --- a/exercises/quiz3.rs +++ b/exercises/quiz3.rs @@ -1,16 +1,32 @@ // quiz3.rs -// This is a quiz for the following sections: -// - Tests +// This quiz tests: +// - Generics +// - Traits +// An imaginary magical school has a new report card generation system written in Rust! +// Currently the system only supports creating report cards where the student's grade +// is represented numerically (e.g. 1.0 -> 5.5). +// However, the school also issues alphabetical grades (A+ -> F-) and needs +// to be able to print both types of report card! -// This quiz isn't testing our function -- make it do that in such a way that -// the test passes. Then write a second test that tests that we get the result -// we expect to get when we call `times_two` with a negative number. -// No hints, you can do this :) +// Make the necessary code changes in the struct ReportCard and the impl block +// to support alphabetical report cards. Change the Grade in the second test to "A+" +// to show that your changes allow alphabetical grades. + +// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE -pub fn times_two(num: i32) -> i32 { - num * 2 +pub struct ReportCard { + pub grade: f32, + pub student_name: String, + pub student_age: u8, +} + +impl ReportCard { + pub fn print(&self) -> String { + format!("{} ({}) - achieved a grade of {}", + &self.student_name, &self.student_age, &self.grade) + } } #[cfg(test)] @@ -18,13 +34,29 @@ mod tests { use super::*; #[test] - fn returns_twice_of_positive_numbers() { - assert_eq!(times_two(4), ???); + fn generate_numeric_report_card() { + let report_card = ReportCard { + grade: 2.1, + student_name: "Tom Wriggle".to_string(), + student_age: 12, + }; + assert_eq!( + report_card.print(), + "Tom Wriggle (12) - achieved a grade of 2.1" + ); } #[test] - fn returns_twice_of_negative_numbers() { - // TODO replace unimplemented!() with an assert for `times_two(-4)` - unimplemented!() + fn generate_alphabetic_report_card() { + // TODO: Make sure to change the grade here after you finish the exercise. + let report_card = ReportCard { + grade: 2.1, + student_name: "Gary Plotter".to_string(), + student_age: 11, + }; + assert_eq!( + report_card.print(), + "Gary Plotter (11) - achieved a grade of A+" + ); } } diff --git a/info.toml b/info.toml index cb49a973..70f66e02 100644 --- a/info.toml +++ b/info.toml @@ -681,19 +681,6 @@ Maybe we could update the explicit references to this data type somehow? If you are still stuck https://doc.rust-lang.org/stable/book/ch10-01-syntax.html#in-method-definitions """ -[[exercises]] -name = "generics3" -path = "exercises/generics/generics3.rs" -mode = "test" -hint = """ -To find the best solution to this challenge you're going to need to think back to your -knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;" - -This is definitely harder than the last two exercises! You need to think about not only making the -ReportCard struct generic, but also the correct property - you will need to change the implementation -of the struct slightly too...you can do it! -""" - # TRAITS [[exercises]] @@ -716,6 +703,16 @@ Try mutating the incoming string vector. Vectors provide suitable methods for adding an element at the end. See the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html""" +# QUIZ 3 + +[[exercises]] +name = "quiz3" +path = "exercises/quiz3.rs" +mode = "test" +hint = """ +To find the best solution to this challenge you're going to need to think back to your +knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;"""" + # TESTS [[exercises]] @@ -748,14 +745,6 @@ You can call a function right where you're passing arguments to `assert!` -- so something like `assert!(having_fun())`. If you want to check that you indeed get false, you can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" -# TEST 3 - -[[exercises]] -name = "quiz3" -path = "exercises/quiz3.rs" -mode = "test" -hint = "No hints this time ;)" - # STANDARD LIBRARY TYPES [[exercises]] From 98b8d3f17d770acf5e618f1e1e62696af6fb00cf Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:14:41 +0200 Subject: [PATCH 359/476] feat(traits): add hint comments --- exercises/traits/traits1.rs | 1 + exercises/traits/traits2.rs | 1 + info.toml | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 15e08f24..5b9d8d50 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -7,6 +7,7 @@ // The trait AppendBar has only one function, // which appends "Bar" to any object // implementing this trait. +// Execute `rustlings hint traits1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 916c3c4b..708bb19a 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -9,6 +9,7 @@ // // No boiler plate code this time, // you can do this! +// Execute `rustlings hint traits2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index 70f66e02..0213878c 100644 --- a/info.toml +++ b/info.toml @@ -698,7 +698,8 @@ path = "exercises/traits/traits2.rs" mode = "test" hint = """ Notice how the trait takes ownership of 'self',and returns `Self'. -Try mutating the incoming string vector. +Try mutating the incoming string vector. Have a look at the tests to see +what the result should look like! Vectors provide suitable methods for adding an element at the end. See the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html""" From 016d718a286f6ccacaecdaa81d9245e96424bae1 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:15:47 +0200 Subject: [PATCH 360/476] feat(tests): add hint comments --- exercises/tests/tests1.rs | 3 ++- exercises/tests/tests2.rs | 3 ++- exercises/tests/tests3.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/exercises/tests/tests1.rs b/exercises/tests/tests1.rs index 50586a19..8b6ea374 100644 --- a/exercises/tests/tests1.rs +++ b/exercises/tests/tests1.rs @@ -4,7 +4,8 @@ // rustlings run tests1 // This test has a problem with it -- make the test compile! Make the test -// pass! Make the test fail! Execute `rustlings hint tests1` for hints :) +// pass! Make the test fail! +// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/tests/tests2.rs b/exercises/tests/tests2.rs index 0d981ad1..a5ac15b1 100644 --- a/exercises/tests/tests2.rs +++ b/exercises/tests/tests2.rs @@ -1,6 +1,7 @@ // tests2.rs // This test has a problem with it -- make the test compile! Make the test -// pass! Make the test fail! Execute `rustlings hint tests2` for hints :) +// pass! Make the test fail! +// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/tests/tests3.rs b/exercises/tests/tests3.rs index 3424f940..196a81a0 100644 --- a/exercises/tests/tests3.rs +++ b/exercises/tests/tests3.rs @@ -2,7 +2,7 @@ // This test isn't testing our function -- make it do that in such a way that // the test passes. Then write a second test that tests whether we get the result // we expect to get when we call `is_even(5)`. -// Execute `rustlings hint tests3` for hints :) +// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From cf9629cb0ea54220085cc33257613157ac830ab1 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:17:23 +0200 Subject: [PATCH 361/476] feat: move box/arc behind iterators --- exercises/standard_library_types/arc1.rs | 2 +- exercises/standard_library_types/box1.rs | 2 +- info.toml | 70 ++++++++++++------------ 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index f60061e7..93a27036 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -16,7 +16,7 @@ // Make this code compile by filling in a value for `shared_numbers` where the // first TODO comment is, and create an initial binding for `child_numbers` // where the second TODO comment is. Try not to create any copies of the `numbers` Vec! -// Execute `rustlings hint arc1` for hints :) +// Execute `rustlings hint arc1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/standard_library_types/box1.rs b/exercises/standard_library_types/box1.rs index f312f3d6..9d9237c1 100644 --- a/exercises/standard_library_types/box1.rs +++ b/exercises/standard_library_types/box1.rs @@ -14,7 +14,7 @@ // // Note: the tests should not be changed // -// Execute `rustlings hint box1` for hints :) +// Execute `rustlings hint box1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index 0213878c..1ba90d18 100644 --- a/info.toml +++ b/info.toml @@ -748,41 +748,6 @@ can negate the result of what you're doing using `!`, like `assert!(!having_fun( # STANDARD LIBRARY TYPES -[[exercises]] -name = "box1" -path = "exercises/standard_library_types/box1.rs" -mode = "test" -hint = """ -Step 1 -The compiler's message should help: since we cannot store the value of the actual type -when working with recursive types, we need to store a reference (pointer) to its value. -We should, therefore, place our `List` inside a `Box`. More details in the book here: -https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes - -Step 2 -Creating an empty list should be fairly straightforward (hint: peek at the assertions). -For a non-empty list keep in mind that we want to use our Cons "list builder". -Although the current list is one of integers (i32), feel free to change the definition -and try other types! -""" - -[[exercises]] -name = "arc1" -path = "exercises/standard_library_types/arc1.rs" -mode = "compile" -hint = """ -Make `shared_numbers` be an `Arc` from the numbers vector. Then, in order -to avoid creating a copy of `numbers`, you'll need to create `child_numbers` -inside the loop but still in the main thread. - -`child_numbers` should be a clone of the Arc of the numbers instead of a -thread-local copy of the numbers. - -This is a simple exercise if you understand the underlying concepts, but if this -is too much of a struggle, consider reading through all of Chapter 16 in the book: -https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html -""" - [[exercises]] name = "iterators1" path = "exercises/standard_library_types/iterators1.rs" @@ -868,6 +833,41 @@ The fold method can be useful in the count_collection_iterator function. For a further challenge, consult the documentation for Iterator to find a different method that could make your code more compact than using fold.""" +[[exercises]] +name = "box1" +path = "exercises/standard_library_types/box1.rs" +mode = "test" +hint = """ +Step 1 +The compiler's message should help: since we cannot store the value of the actual type +when working with recursive types, we need to store a reference (pointer) to its value. +We should, therefore, place our `List` inside a `Box`. More details in the book here: +https://doc.rust-lang.org/book/ch15-01-box.html#enabling-recursive-types-with-boxes + +Step 2 +Creating an empty list should be fairly straightforward (hint: peek at the assertions). +For a non-empty list keep in mind that we want to use our Cons "list builder". +Although the current list is one of integers (i32), feel free to change the definition +and try other types! +""" + +[[exercises]] +name = "arc1" +path = "exercises/standard_library_types/arc1.rs" +mode = "compile" +hint = """ +Make `shared_numbers` be an `Arc` from the numbers vector. Then, in order +to avoid creating a copy of `numbers`, you'll need to create `child_numbers` +inside the loop but still in the main thread. + +`child_numbers` should be a clone of the Arc of the numbers instead of a +thread-local copy of the numbers. + +This is a simple exercise if you understand the underlying concepts, but if this +is too much of a struggle, consider reading through all of Chapter 16 in the book: +https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html +""" + # THREADS [[exercises]] From 3c63ef06683410b63f191b3e43a7e499e9a02d33 Mon Sep 17 00:00:00 2001 From: Ryosuke YASUOKA Date: Fri, 14 Jan 2022 00:26:46 +0900 Subject: [PATCH 362/476] fix(iterators3): insert todo!() into divide() to compile without error --- exercises/standard_library_types/iterators3.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/exercises/standard_library_types/iterators3.rs b/exercises/standard_library_types/iterators3.rs index 8c66c05b..ec2e36d1 100644 --- a/exercises/standard_library_types/iterators3.rs +++ b/exercises/standard_library_types/iterators3.rs @@ -22,7 +22,9 @@ pub struct NotDivisibleError { // Calculate `a` divided by `b` if `a` is evenly divisible by `b`. // Otherwise, return a suitable error. -pub fn divide(a: i32, b: i32) -> Result {} +pub fn divide(a: i32, b: i32) -> Result { + todo!(); +} // Complete the function and return a value of the correct type so the test passes. // Desired output: Ok([1, 11, 1426, 3]) From 251d0dda345e6b3d067232a32db7afad098c8522 Mon Sep 17 00:00:00 2001 From: Paulo Gabriel Justino Bezerra Date: Thu, 13 Jan 2022 18:11:52 -0300 Subject: [PATCH 363/476] feat(iterators4): add factorial of zero test --- exercises/standard_library_types/iterators4.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/exercises/standard_library_types/iterators4.rs b/exercises/standard_library_types/iterators4.rs index 88862838..0b3b5d88 100644 --- a/exercises/standard_library_types/iterators4.rs +++ b/exercises/standard_library_types/iterators4.rs @@ -18,6 +18,11 @@ pub fn factorial(num: u64) -> u64 { mod tests { use super::*; + #[test] + fn factorial_of_0() { + assert_eq!(1, factorial(0)); + } + #[test] fn factorial_of_1() { assert_eq!(1, factorial(1)); From 20024d40c5e121202f283b420d7da1deecf4ebc0 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:29:09 +0200 Subject: [PATCH 364/476] feat(iterators): update hint comments --- exercises/standard_library_types/iterators1.rs | 2 +- exercises/standard_library_types/iterators2.rs | 2 +- exercises/standard_library_types/iterators3.rs | 2 +- exercises/standard_library_types/iterators4.rs | 1 + exercises/standard_library_types/iterators5.rs | 4 +++- info.toml | 7 +++++-- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/exercises/standard_library_types/iterators1.rs b/exercises/standard_library_types/iterators1.rs index 5aa49b64..0379c6bb 100644 --- a/exercises/standard_library_types/iterators1.rs +++ b/exercises/standard_library_types/iterators1.rs @@ -6,7 +6,7 @@ // 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 +// Execute `rustlings hint iterators1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/standard_library_types/iterators2.rs b/exercises/standard_library_types/iterators2.rs index 87b4eaa1..29c53afb 100644 --- a/exercises/standard_library_types/iterators2.rs +++ b/exercises/standard_library_types/iterators2.rs @@ -1,7 +1,7 @@ // iterators2.rs // In this exercise, you'll learn some of the unique advantages that iterators // can offer. Follow the steps to complete the exercise. -// As always, there are hints if you execute `rustlings hint iterators2`! +// Execute `rustlings hint iterators2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/standard_library_types/iterators3.rs b/exercises/standard_library_types/iterators3.rs index ec2e36d1..c97a6258 100644 --- a/exercises/standard_library_types/iterators3.rs +++ b/exercises/standard_library_types/iterators3.rs @@ -4,7 +4,7 @@ // 1. Complete the divide function to get the first four tests to pass. // 2. Get the remaining tests to pass by completing the result_with_list and // list_of_results functions. -// Execute `rustlings hint iterators3` to get some hints! +// Execute `rustlings hint iterators3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/standard_library_types/iterators4.rs b/exercises/standard_library_types/iterators4.rs index 0b3b5d88..a02470ec 100644 --- a/exercises/standard_library_types/iterators4.rs +++ b/exercises/standard_library_types/iterators4.rs @@ -1,4 +1,5 @@ // iterators4.rs +// Execute `rustlings hint iterators4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/standard_library_types/iterators5.rs b/exercises/standard_library_types/iterators5.rs index 93f3ae11..0593d123 100644 --- a/exercises/standard_library_types/iterators5.rs +++ b/exercises/standard_library_types/iterators5.rs @@ -6,7 +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` or use the `hint` watch subcommand for a hint. // // Make the code compile and the tests pass. @@ -34,6 +34,7 @@ fn count_for(map: &HashMap, value: Progress) -> usize { fn count_iterator(map: &HashMap, value: Progress) -> usize { // map is a hashmap with String keys and Progress values. // map = { "variables1": Complete, "from_str": None, ... } + todo!(); } fn count_collection_for(collection: &[HashMap], value: Progress) -> usize { @@ -52,6 +53,7 @@ fn count_collection_iterator(collection: &[HashMap], value: Pr // collection is a slice of hashmaps. // collection = [{ "variables1": Complete, "from_str": None, ... }, // { "variables2": Complete, ... }, ... ] + todo!(); } #[cfg(test)] diff --git a/info.toml b/info.toml index 1ba90d18..33f126e1 100644 --- a/info.toml +++ b/info.toml @@ -802,7 +802,8 @@ 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 for how -the `FromIterator` trait is used in `collect()`.""" +the `FromIterator` trait is used in `collect()`. This trait is REALLY powerful! It +can make the solution to this exercise infinitely easier.""" [[exercises]] name = "iterators4" @@ -812,7 +813,9 @@ hint = """ In an imperative language, you might write a for loop that updates a mutable variable. Or, you might write code utilizing recursion and a match clause. In Rust you can take another functional -approach, computing the factorial elegantly with ranges and iterators.""" +approach, computing the factorial elegantly with ranges and iterators. + +Hint 2: Check out the `fold` and `rfold` methods!""" [[exercises]] name = "iterators5" From 3e7e65b9f0e6e9a2f8ddd55f8403a5e3c2c852da Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:29:50 +0000 Subject: [PATCH 365/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 720db577..229e0759 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -186,6 +186,7 @@ authors.
YsuOS

🖋
Steven Nguyen

🖋
nacairns1

🖋 +
Paulo Gabriel Justino Bezerra

🖋 From 09ccadeec64e447a07868f4abd1cc2af577623de Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:29:51 +0000 Subject: [PATCH 366/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index e2c0bc2a..ddd5d057 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1308,6 +1308,15 @@ "contributions": [ "content" ] + }, + { + "login": "pgjbz", + "name": "Paulo Gabriel Justino Bezerra", + "avatar_url": "https://avatars.githubusercontent.com/u/22059237?v=4", + "profile": "https://github.com/pgjbz", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From b4f52cb937e9f2b90913402964ae014240705a5f Mon Sep 17 00:00:00 2001 From: jaystile <46078028+jaystile@users.noreply.github.com> Date: Thu, 23 Dec 2021 06:19:39 -0800 Subject: [PATCH 367/476] feat: Adding threads1.rs with a focus on JoinHandles and waiting for spawned threads to finish. Moved the original threads1.rs to threads2.rs with the focus on the Mutex and modifying shared data. #892 --- exercises/threads/threads1.rs | 39 +++++++++++++++++------------------ exercises/threads/threads2.rs | 34 ++++++++++++++++++++++++++++++ info.toml | 24 ++++++++++++++------- 3 files changed, 69 insertions(+), 28 deletions(-) create mode 100644 exercises/threads/threads2.rs diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index f31b317e..ddb61552 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -1,32 +1,31 @@ // threads1.rs -// Make this compile! Execute `rustlings hint threads1` for hints :) -// The idea is the thread spawned on line 22 is completing jobs while the main thread is -// monitoring progress until 10 jobs are completed. Because of the difference between the -// spawned threads' sleep time, and the waiting threads sleep time, when you see 6 lines -// of "waiting..." and the program ends without timing out when running, -// you've got it :) +// Make this compile and run! Execute 'rustlings hint threads1' for hints :) +// This program should wait until all the spawned threads have finished before exiting. // I AM NOT DONE -use std::sync::Arc; use std::thread; use std::time::Duration; -struct JobStatus { - jobs_completed: u32, -} fn main() { - let status = Arc::new(JobStatus { jobs_completed: 0 }); - let status_shared = status.clone(); - thread::spawn(move || { - for _ in 0..10 { + + let mut handles = vec![]; + for i in 0..10 { + thread::spawn(move || { thread::sleep(Duration::from_millis(250)); - status_shared.jobs_completed += 1; - } - }); - while status.jobs_completed < 10 { - println!("waiting... "); - thread::sleep(Duration::from_millis(500)); + println!("thread {} is complete", i); + }); } + + let mut completed_threads = 0; + for handle in handles { + // TODO: a struct is returned from thread::spawn, can you use it? + completed_threads += 1; + } + + if completed_threads != 10 { + panic!("Oh no! All the spawned threads did not finish!"); + } + } diff --git a/exercises/threads/threads2.rs b/exercises/threads/threads2.rs new file mode 100644 index 00000000..2cb0d041 --- /dev/null +++ b/exercises/threads/threads2.rs @@ -0,0 +1,34 @@ +// threads2.rs +// Make this compile! Execute `rustlings hint threads2` for hints :) +// Building on the last exercise, we want all of the threads to complete their work but this time +// the spawned threads need to be in charge of updating a shared value: JobStatus.jobs_completed + +// I AM NOT DONE + +use std::sync::Arc; +use std::thread; +use std::time::Duration; + +struct JobStatus { + jobs_completed: u32, +} + +fn main() { + let status = Arc::new(JobStatus { jobs_completed: 0 }); + let mut handles = vec![]; + for _ in 0..10 { + let status_shared = status.clone(); + let handle = thread::spawn(move || { + thread::sleep(Duration::from_millis(250)); + // TODO: You must take an action before you update a shared value + status_shared.jobs_completed += 1; + }); + handles.push(handle); + } + for handle in handles { + handle.join().unwrap(); + // TODO: Print the value of the JobStatus.jobs_completed. Did you notice anything + // interesting in the output? Do you have to 'join' on all the handles? + println!("jobs completed {}", ???); + } +} diff --git a/info.toml b/info.toml index 33f126e1..94d5bf86 100644 --- a/info.toml +++ b/info.toml @@ -878,6 +878,22 @@ name = "threads1" path = "exercises/threads/threads1.rs" mode = "compile" hint = """ +`JoinHandle` is a struct that is returned from a spawned thread: +https://doc.rust-lang.org/std/thread/fn.spawn.html + +A challenge with multi-threaded applications is that the main thread can +finish before the spawned threads are completed. +https://doc.rust-lang.org/book/ch16-01-threads.html#waiting-for-all-threads-to-finish-using-join-handle + +Collect the JoinHandles and wait for them to finish. +https://doc.rust-lang.org/std/thread/struct.JoinHandle.html +""" + +[[exercises]] +name = "threads2" +path = "exercises/threads/threads2.rs" +mode = "compile" +hint = """ `Arc` is an Atomic Reference Counted pointer that allows safe, shared access to **immutable** data. But we want to *change* the number of `jobs_completed` so we'll need to also use another type that will only allow one thread to @@ -898,14 +914,6 @@ while they are sleeping, since this will prevent the other thread from being allowed to get the lock. Locks are automatically released when they go out of scope. -Ok, so, real talk, this was actually tricky for *me* to do too. And -I could see a lot of different problems you might run into, so at this -point I'm not sure which one you've hit :) - -Please open an issue if you're still running into a problem that -these hints are not helping you with, or if you've looked at the sample -answers and don't understand why they work and yours doesn't. - If you've learned from the sample solutions, I encourage you to come back to this exercise and try it again in a few days to reinforce what you've learned :)""" From f99eafc56f49852d4b801b5c4cfedf47ef4968ae Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 11:59:53 +0200 Subject: [PATCH 368/476] fix(threads): add hint comments --- exercises/threads/threads1.rs | 2 +- exercises/threads/threads2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/threads/threads1.rs b/exercises/threads/threads1.rs index ddb61552..e59f4ce4 100644 --- a/exercises/threads/threads1.rs +++ b/exercises/threads/threads1.rs @@ -1,5 +1,5 @@ // threads1.rs -// Make this compile and run! Execute 'rustlings hint threads1' for hints :) +// Execute `rustlings hint threads1` or use the `hint` watch subcommand for a hint. // This program should wait until all the spawned threads have finished before exiting. // I AM NOT DONE diff --git a/exercises/threads/threads2.rs b/exercises/threads/threads2.rs index 2cb0d041..d0f8578f 100644 --- a/exercises/threads/threads2.rs +++ b/exercises/threads/threads2.rs @@ -1,5 +1,5 @@ // threads2.rs -// Make this compile! Execute `rustlings hint threads2` for hints :) +// Execute `rustlings hint threads2` or use the `hint` watch subcommand for a hint. // Building on the last exercise, we want all of the threads to complete their work but this time // the spawned threads need to be in charge of updating a shared value: JobStatus.jobs_completed From 7b371afc0638ddb56dc7c706384272a886fce3c6 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 10:01:48 +0000 Subject: [PATCH 369/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 229e0759..53044946 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -187,6 +187,7 @@ authors.
Steven Nguyen

🖋
nacairns1

🖋
Paulo Gabriel Justino Bezerra

🖋 +
Jason

🖋 From b1f82890c9aaec6f642b71c99c11712d965b35cb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 10:01:49 +0000 Subject: [PATCH 370/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index ddd5d057..7bdfe974 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1317,6 +1317,15 @@ "contributions": [ "content" ] + }, + { + "login": "jaystile", + "name": "Jason", + "avatar_url": "https://avatars.githubusercontent.com/u/46078028?v=4", + "profile": "https://github.com/jaystile", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d3a335bc64234738adb9d7514a5930bd6f9d38ee Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:05:26 +0200 Subject: [PATCH 371/476] feat(macros): add hint comments --- exercises/macros/macros1.rs | 2 +- exercises/macros/macros2.rs | 2 +- exercises/macros/macros3.rs | 2 +- exercises/macros/macros4.rs | 2 +- info.toml | 7 ++++++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/exercises/macros/macros1.rs b/exercises/macros/macros1.rs index ed0dac85..634d0a70 100644 --- a/exercises/macros/macros1.rs +++ b/exercises/macros/macros1.rs @@ -1,5 +1,5 @@ // macros1.rs -// Make me compile! Execute `rustlings hint macros1` for hints :) +// Execute `rustlings hint macros1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/macros/macros2.rs b/exercises/macros/macros2.rs index d0be1236..f6092cab 100644 --- a/exercises/macros/macros2.rs +++ b/exercises/macros/macros2.rs @@ -1,5 +1,5 @@ // macros2.rs -// Make me compile! Execute `rustlings hint macros2` for hints :) +// Execute `rustlings hint macros2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/macros/macros3.rs b/exercises/macros/macros3.rs index 93a43113..106f1c6d 100644 --- a/exercises/macros/macros3.rs +++ b/exercises/macros/macros3.rs @@ -1,6 +1,6 @@ // macros3.rs // Make me compile, without taking the macro out of the module! -// Execute `rustlings hint macros3` for hints :) +// Execute `rustlings hint macros3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index 3a748078..c1fc5e8b 100644 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -1,5 +1,5 @@ // macros4.rs -// Make me compile! Execute `rustlings hint macros4` for hints :) +// Execute `rustlings hint macros4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/info.toml b/info.toml index 94d5bf86..1e7fa1ad 100644 --- a/info.toml +++ b/info.toml @@ -958,7 +958,12 @@ mode = "compile" hint = """ You only need to add a single character to make this compile. The way macros are written, it wants to see something between each -"macro arm", so it can separate them.""" +"macro arm", so it can separate them. + +That's all the macro exercises we have in here, but it's barely even +scratching the surface of what you can do with Rust's macros. For a more +thorough introduction, you can have a read through the little book of Rust +macros: https://veykril.github.io/tlborm/""" # TEST 4 From 7fc393bed4689d4e106a199dd956bef796976935 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:13:40 +0200 Subject: [PATCH 372/476] chore: remove quiz4 --- exercises/quiz4.rs | 23 ----------------------- info.toml | 8 -------- 2 files changed, 31 deletions(-) delete mode 100644 exercises/quiz4.rs diff --git a/exercises/quiz4.rs b/exercises/quiz4.rs deleted file mode 100644 index 6c47480d..00000000 --- a/exercises/quiz4.rs +++ /dev/null @@ -1,23 +0,0 @@ -// quiz4.rs -// This quiz covers the sections: -// - Modules -// - Macros - -// Write a macro that passes the quiz! No hints this time, you can do it! - -// I AM NOT DONE - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_my_macro_world() { - assert_eq!(my_macro!("world!"), "Hello world!"); - } - - #[test] - fn test_my_macro_goodbye() { - assert_eq!(my_macro!("goodbye!"), "Hello goodbye!"); - } -} diff --git a/info.toml b/info.toml index 1e7fa1ad..95674955 100644 --- a/info.toml +++ b/info.toml @@ -965,14 +965,6 @@ scratching the surface of what you can do with Rust's macros. For a more thorough introduction, you can have a read through the little book of Rust macros: https://veykril.github.io/tlborm/""" -# TEST 4 - -[[exercises]] -name = "quiz4" -path = "exercises/quiz4.rs" -mode = "test" -hint = "No hints this time ;)" - # CLIPPY [[exercises]] From 8cfedb16738e613ab90894386e299f5cb6292932 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:28:47 +0200 Subject: [PATCH 373/476] feat(clippy): add clippy3 --- .gitignore | 1 + exercises/clippy/clippy1.rs | 2 +- exercises/clippy/clippy2.rs | 2 +- exercises/clippy/clippy3.rs | 26 ++++++++++++++++++++++++++ info.toml | 6 ++++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 exercises/clippy/clippy3.rs diff --git a/.gitignore b/.gitignore index 253d85bd..534453bc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ rust-project.json .idea .vscode *.iml +*.o diff --git a/exercises/clippy/clippy1.rs b/exercises/clippy/clippy1.rs index c5f84a9c..bad46891 100644 --- a/exercises/clippy/clippy1.rs +++ b/exercises/clippy/clippy1.rs @@ -4,7 +4,7 @@ // // For these exercises the code will fail to compile when there are clippy warnings // check clippy's suggestions from the output to solve the exercise. -// Execute `rustlings hint clippy1` for hints :) +// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/clippy/clippy2.rs b/exercises/clippy/clippy2.rs index 37af9ed0..dac40dbe 100644 --- a/exercises/clippy/clippy2.rs +++ b/exercises/clippy/clippy2.rs @@ -1,5 +1,5 @@ // clippy2.rs -// Make me compile! Execute `rustlings hint clippy2` for hints :) +// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/clippy/clippy3.rs b/exercises/clippy/clippy3.rs new file mode 100644 index 00000000..13733c0b --- /dev/null +++ b/exercises/clippy/clippy3.rs @@ -0,0 +1,26 @@ +// clippy3.rs +// Here's a couple more easy Clippy fixes, so you can see its utility. + +#[allow(unused_variables, unused_assignments)] +fn main() { + let my_option: Option<()> = None; + if my_option.is_none() { + my_option.unwrap(); + } + + let my_arr = &[ + -1, -2, -3 + -4, -5, -6 + ]; + println!("My array! Here it is: {:?}", my_arr); + + let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5); + println!("This Vec is empty, see? {:?}", my_empty_vec); + + let mut value_a = 45; + let mut value_b = 66; + // Let's swap these two! + value_a = value_b; + value_b = value_a; + println!("value a: {}; value b: {}", value_a, value_b); +} diff --git a/info.toml b/info.toml index 95674955..3c37f95b 100644 --- a/info.toml +++ b/info.toml @@ -989,6 +989,12 @@ mode = "clippy" hint = """ `for` loops over Option values are more clearly expressed as an `if let`""" +[[exercises]] +name = "clippy3" +path = "exercises/clippy/clippy3.rs" +mode = "clippy" +hint = "No hints this time!" + # TYPE CONVERSIONS [[exercises]] From 74f44f55e381384dc89ec421568aa1509cd7f277 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:34:10 +0200 Subject: [PATCH 374/476] feat(conversions): add hint comments --- exercises/conversions/from_into.rs | 2 ++ exercises/conversions/from_str.rs | 5 +++++ exercises/conversions/try_from_into.rs | 2 ++ exercises/conversions/using_as.rs | 1 + 4 files changed, 10 insertions(+) diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index 9d84174d..6c272c3b 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -1,6 +1,8 @@ // The From trait is used for value-to-value conversions. // If From is implemented correctly for a type, the Into trait should work conversely. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.From.html +// Execute `rustlings hint from_into` or use the `hint` watch subcommand for a hint. + #[derive(Debug)] struct Person { name: String, diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index ece0b3cf..fe168159 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -4,6 +4,8 @@ // Additionally, upon implementing FromStr, you can use the `parse` method // on strings to generate an object of the implementor type. // You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html +// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint. + use std::num::ParseIntError; use std::str::FromStr; @@ -37,6 +39,9 @@ enum ParsePersonError { // with something like `"4".parse::()` // 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 +// +// As an aside: `Box` implements `From<&'_ str>`. This means that if you want to return a +// string error message, you can do so via just using return `Err("my error message".into())`. impl FromStr for Person { type Err = ParsePersonError; diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index b8ec4455..09f730eb 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -3,6 +3,8 @@ // Basically, this is the same as From. The main difference is that this should return a Result type // instead of the target type itself. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html +// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint. + use std::convert::{TryFrom, TryInto}; #[derive(Debug, PartialEq)] diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index f3f745ff..8c9b7113 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -4,6 +4,7 @@ // // The goal is to make sure that the division does not fail to compile // and returns the proper type. +// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 81d25aecff01643221131743b48f6b63377eeb59 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:49:49 +0200 Subject: [PATCH 375/476] feat(try_from_into): add hint comments --- exercises/conversions/try_from_into.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 09f730eb..bc71a3c3 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -3,7 +3,7 @@ // Basically, this is the same as From. The main difference is that this should return a Result type // instead of the target type itself. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html -// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint. +// Execute `rustlings hint try_from_into` or use the `hint` watch subcommand for a hint. use std::convert::{TryFrom, TryInto}; From 4bebdb5f02f492081568900b739ad76dc05ea4ef Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:50:01 +0200 Subject: [PATCH 376/476] feat(as_ref_mut): add AsMut section --- exercises/conversions/as_ref_mut.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index 84f4a60c..9f479739 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -1,6 +1,7 @@ // AsRef and AsMut allow for cheap reference-to-reference conversions. // Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html // and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively. +// Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -16,10 +17,10 @@ fn char_counter(arg: T) -> usize { arg.as_ref().chars().count() } -fn main() { - let s = "Café au lait"; - println!("{}", char_counter(s)); - println!("{}", byte_counter(s)); +// Squares a number using AsMut. Add the trait bound as is appropriate and +// implement the function body. +fn num_sq(arg: &mut T) { + ??? } #[cfg(test)] @@ -49,4 +50,11 @@ mod tests { let s = String::from("Cafe au lait"); assert_eq!(char_counter(s.clone()), byte_counter(s)); } + + #[test] + fn mult_box() { + let mut num: Box = Box::new(3); + num_sq(&mut num); + assert_eq!(*num, 9); + } } From b609f0431c0031c8aa9113fea4de4b23db05cf77 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:51:12 +0200 Subject: [PATCH 377/476] feat: remove advanced_errs --- exercises/advanced_errors/advanced_errs1.rs | 98 ---------- exercises/advanced_errors/advanced_errs2.rs | 202 -------------------- info.toml | 52 ----- 3 files changed, 352 deletions(-) delete mode 100644 exercises/advanced_errors/advanced_errs1.rs delete mode 100644 exercises/advanced_errors/advanced_errs2.rs diff --git a/exercises/advanced_errors/advanced_errs1.rs b/exercises/advanced_errors/advanced_errs1.rs deleted file mode 100644 index 4bc7b635..00000000 --- a/exercises/advanced_errors/advanced_errs1.rs +++ /dev/null @@ -1,98 +0,0 @@ -// advanced_errs1.rs - -// Remember back in errors6, we had multiple mapping functions so that we -// could translate lower-level errors into our custom error type using -// `map_err()`? What if we could use the `?` operator directly instead? - -// Make this code compile! Execute `rustlings hint advanced_errs1` for -// hints :) - -// I AM NOT DONE - -use std::num::ParseIntError; -use std::str::FromStr; - -// This is a custom error type that we will be using in the `FromStr` -// implementation. -#[derive(PartialEq, Debug)] -enum ParsePosNonzeroError { - Creation(CreationError), - ParseInt(ParseIntError), -} - -impl From for ParsePosNonzeroError { - fn from(e: CreationError) -> Self { - // TODO: complete this implementation so that the `?` operator will - // work for `CreationError` - } -} - -// TODO: implement another instance of the `From` trait here so that the -// `?` operator will work in the other place in the `FromStr` -// implementation below. - -// Don't change anything below this line. - -impl FromStr for PositiveNonzeroInteger { - type Err = ParsePosNonzeroError; - fn from_str(s: &str) -> Result { - let x: i64 = s.parse()?; - Ok(PositiveNonzeroInteger::new(x)?) - } -} - -#[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() { - // We can't construct a ParseIntError, so we have to pattern match. - assert!(matches!( - PositiveNonzeroInteger::from_str("not a number"), - Err(ParsePosNonzeroError::ParseInt(_)) - )); - } - - #[test] - fn test_negative() { - assert_eq!( - PositiveNonzeroInteger::from_str("-555"), - Err(ParsePosNonzeroError::Creation(CreationError::Negative)) - ); - } - - #[test] - fn test_zero() { - assert_eq!( - PositiveNonzeroInteger::from_str("0"), - Err(ParsePosNonzeroError::Creation(CreationError::Zero)) - ); - } - - #[test] - fn test_positive() { - let x = PositiveNonzeroInteger::new(42); - assert!(x.is_ok()); - assert_eq!(PositiveNonzeroInteger::from_str("42"), Ok(x.unwrap())); - } -} diff --git a/exercises/advanced_errors/advanced_errs2.rs b/exercises/advanced_errors/advanced_errs2.rs deleted file mode 100644 index 54e669fd..00000000 --- a/exercises/advanced_errors/advanced_errs2.rs +++ /dev/null @@ -1,202 +0,0 @@ -// advanced_errs2.rs - -// This exercise demonstrates a few traits that are useful for custom error -// types to implement, especially so that other code can consume the custom -// error type more usefully. - -// Make this compile, and make the tests pass! -// Execute `rustlings hint advanced_errs2` for hints. - -// Steps: -// 1. Implement a missing trait so that `main()` will compile. -// 2. Complete the partial implementation of `From` for -// `ParseClimateError`. -// 3. Handle the missing error cases in the `FromStr` implementation for -// `Climate`. -// 4. Complete the partial implementation of `Display` for -// `ParseClimateError`. - -// I AM NOT DONE - -use std::error::Error; -use std::fmt::{self, Display, Formatter}; -use std::num::{ParseFloatError, ParseIntError}; -use std::str::FromStr; - -// This is the custom error type that we will be using for the parser for -// `Climate`. -#[derive(Debug, PartialEq)] -enum ParseClimateError { - Empty, - BadLen, - NoCity, - ParseInt(ParseIntError), - ParseFloat(ParseFloatError), -} - -// This `From` implementation allows the `?` operator to work on -// `ParseIntError` values. -impl From for ParseClimateError { - fn from(e: ParseIntError) -> Self { - Self::ParseInt(e) - } -} - -// This `From` implementation allows the `?` operator to work on -// `ParseFloatError` values. -impl From for ParseClimateError { - fn from(e: ParseFloatError) -> Self { - // TODO: Complete this function - } -} - -// TODO: Implement a missing trait so that `main()` below will compile. It -// is not necessary to implement any methods inside the missing trait. - -// The `Display` trait allows for other code to obtain the error formatted -// as a user-visible string. -impl Display for ParseClimateError { - // TODO: Complete this function so that it produces the correct strings - // for each error variant. - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - // Imports the variants to make the following code more compact. - use ParseClimateError::*; - match self { - NoCity => write!(f, "no city name"), - ParseFloat(e) => write!(f, "error parsing temperature: {}", e), - } - } -} - -#[derive(Debug, PartialEq)] -struct Climate { - city: String, - year: u32, - temp: f32, -} - -// Parser for `Climate`. -// 1. Split the input string into 3 fields: city, year, temp. -// 2. Return an error if the string is empty or has the wrong number of -// fields. -// 3. Return an error if the city name is empty. -// 4. Parse the year as a `u32` and return an error if that fails. -// 5. Parse the temp as a `f32` and return an error if that fails. -// 6. Return an `Ok` value containing the completed `Climate` value. -impl FromStr for Climate { - type Err = ParseClimateError; - // TODO: Complete this function by making it handle the missing error - // cases. - fn from_str(s: &str) -> Result { - let v: Vec<_> = s.split(',').collect(); - let (city, year, temp) = match &v[..] { - [city, year, temp] => (city.to_string(), year, temp), - _ => return Err(ParseClimateError::BadLen), - }; - let year: u32 = year.parse()?; - let temp: f32 = temp.parse()?; - Ok(Climate { city, year, temp }) - } -} - -// Don't change anything below this line (other than to enable ignored -// tests). - -fn main() -> Result<(), Box> { - println!("{:?}", "Hong Kong,1999,25.7".parse::()?); - println!("{:?}", "".parse::()?); - Ok(()) -} - -#[cfg(test)] -mod test { - use super::*; - #[test] - fn test_empty() { - let res = "".parse::(); - assert_eq!(res, Err(ParseClimateError::Empty)); - assert_eq!(res.unwrap_err().to_string(), "empty input"); - } - #[test] - fn test_short() { - let res = "Boston,1991".parse::(); - assert_eq!(res, Err(ParseClimateError::BadLen)); - assert_eq!(res.unwrap_err().to_string(), "incorrect number of fields"); - } - #[test] - fn test_long() { - let res = "Paris,1920,17.2,extra".parse::(); - assert_eq!(res, Err(ParseClimateError::BadLen)); - assert_eq!(res.unwrap_err().to_string(), "incorrect number of fields"); - } - #[test] - fn test_no_city() { - let res = ",1997,20.5".parse::(); - assert_eq!(res, Err(ParseClimateError::NoCity)); - assert_eq!(res.unwrap_err().to_string(), "no city name"); - } - #[test] - fn test_parse_int_neg() { - let res = "Barcelona,-25,22.3".parse::(); - assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); - let err = res.unwrap_err(); - if let ParseClimateError::ParseInt(ref inner) = err { - assert_eq!( - err.to_string(), - format!("error parsing year: {}", inner.to_string()) - ); - } else { - unreachable!(); - }; - } - #[test] - fn test_parse_int_bad() { - let res = "Beijing,foo,15.0".parse::(); - assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); - let err = res.unwrap_err(); - if let ParseClimateError::ParseInt(ref inner) = err { - assert_eq!( - err.to_string(), - format!("error parsing year: {}", inner.to_string()) - ); - } else { - unreachable!(); - }; - } - #[test] - fn test_parse_float() { - let res = "Manila,2001,bar".parse::(); - assert!(matches!(res, Err(ParseClimateError::ParseFloat(_)))); - let err = res.unwrap_err(); - if let ParseClimateError::ParseFloat(ref inner) = err { - assert_eq!( - err.to_string(), - format!("error parsing temperature: {}", inner.to_string()) - ); - } else { - unreachable!(); - }; - } - #[test] - fn test_parse_good() { - let res = "Munich,2015,23.1".parse::(); - assert_eq!( - res, - Ok(Climate { - city: "Munich".to_string(), - year: 2015, - temp: 23.1, - }) - ); - } - #[test] - #[ignore] - fn test_downcast() { - let res = "São Paulo,-21,28.5".parse::(); - assert!(matches!(res, Err(ParseClimateError::ParseInt(_)))); - let err = res.unwrap_err(); - let inner: Option<&(dyn Error + 'static)> = err.source(); - assert!(inner.is_some()); - assert!(inner.unwrap().is::()); - } -} diff --git a/info.toml b/info.toml index 3c37f95b..c239121d 100644 --- a/info.toml +++ b/info.toml @@ -1061,55 +1061,3 @@ path = "exercises/conversions/as_ref_mut.rs" mode = "test" hint = """ Add AsRef as a trait bound to the functions.""" - -# ADVANCED ERRORS - -[[exercises]] -name = "advanced_errs1" -path = "exercises/advanced_errors/advanced_errs1.rs" -mode = "test" -hint = """ -This exercise uses an updated version of the code in errors6. The parsing -code is now in an implementation of the `FromStr` trait. Note that the -parsing code uses `?` directly, without any calls to `map_err()`. There is -one partial implementation of the `From` trait example that you should -complete. - -Details: The `?` operator calls `From::from()` on the error type to convert -it to the error type of the return type of the surrounding function. - -Hint: You will need to write another implementation of `From` that has a -different input type. -""" - -[[exercises]] -name = "advanced_errs2" -path = "exercises/advanced_errors/advanced_errs2.rs" -mode = "test" -hint = """ -This exercise demonstrates a few traits that are useful for custom error -types to implement. These traits make it easier for other code to consume -the custom error type. - -Follow the steps in the comment near the top of the file. You will have to -supply a missing trait implementation, and complete a few incomplete ones. - -You may find these pages to be helpful references: -https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/define_error_type.html -https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html -https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/wrap_error.html - -Hint: What trait must our error type have for `main()` to return the return -type that it returns? - -Another hint: It's not necessary to implement any methods inside the missing -trait. (Some methods have default implementations that are supplied by the -trait.) - -Another hint: Consult the tests to determine which error variants (and which -error message text) to produce for certain error conditions. - -Challenge: There is one test that is marked `#[ignore]`. Can you supply the -missing code that will make it pass? You may want to consult the standard -library documentation for a certain trait for more hints. -""" From 0784f54141325bf9b6dbea886aaa5002f7cc9a75 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 12:57:54 +0200 Subject: [PATCH 378/476] doc: update contributing --- CONTRIBUTING.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ca0e341..cc8ac923 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ _implement a new feature! ➡️ [open an Issue to discuss it first, then a Pull `rustlings` is basically a glorified `rustc` wrapper. Therefore the source code isn't really that complicated since the bulk of the work is done by `rustc`. -`src/main.rs` contains a simple `clap` CLI that loads from `src/verify.rs` and `src/run.rs`. +`src/main.rs` contains a simple `argh` CLI that connects to most of the other source files. ### Adding an exercise @@ -29,7 +29,7 @@ isn't really that complicated since the bulk of the work is done by `rustc`. The first step is to add the exercise! Name the file `exercises/yourTopic/yourTopicN.rs`, make sure to put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`. -Next make sure it runs with `rustlings`. The exercise metadata is stored in `info.toml`, under the `exercises` array. The order of the `exercises` array determines the order the exercises are run by `rustlings verify`. +Next make sure it runs with `rustlings`. The exercise metadata is stored in `info.toml`, under the `exercises` array. The order of the `exercises` array determines the order the exercises are run by `rustlings verify` and `rustlings watch`. Add the metadata for your exercise in the correct order in the `exercises` array. If you are unsure of the correct ordering, add it at the bottom and ask in your pull request. The exercise metadata should contain the following: ```diff @@ -43,7 +43,7 @@ Add the metadata for your exercise in the correct order in the `exercises` array ... ``` -The `mode` attribute decides whether Rustlings will only compile your exercise, or compile and test it. If you have tests to verify in your exercise, choose `test`, otherwise `compile`. +The `mode` attribute decides whether Rustlings will only compile your exercise, or compile and test it. If you have tests to verify in your exercise, choose `test`, otherwise `compile`. If you're working on a Clippy exercise, use `mode = "clippy"`. That's all! Feel free to put up a pull request. @@ -67,19 +67,19 @@ changes. There's a couple of things to watch out for: #### Write correct commit messages We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.4/) -specification, because it makes it easier to generate changelogs automatically. +specification. This means that you have to format your commit messages in a specific way. Say you're working on adding a new exercise called `foobar1.rs`. You could write the following commit message: ``` -feat: Add foobar1.rs exercise +feat: add foobar1.rs exercise ``` If you're just fixing a bug, please use the `fix` type: ``` -fix(verify): Make sure verify doesn't self-destruct +fix(verify): make sure verify doesn't self-destruct ``` The scope within the brackets is optional, but should be any of these: @@ -96,7 +96,7 @@ When the commit also happens to close an existing issue, link it in the message body: ``` -fix: Update foobar +fix: update foobar closes #101029908 ``` @@ -104,13 +104,13 @@ closes #101029908 If you're doing simple changes, like updating a book link, use `chore`: ``` -chore: Update exercise1.rs book link +chore: update exercise1.rs book link ``` If you're updating documentation, use `docs`: ``` -docs: Add more information to Readme +docs: add more information to Readme ``` If, and only if, you're absolutely sure you want to make a breaking change @@ -118,7 +118,7 @@ If, and only if, you're absolutely sure you want to make a breaking change explain the breaking change in the message body: ``` -fix!: Completely change verification +fix!: completely change verification BREAKING CHANGE: This has to be done because lorem ipsum dolor ``` @@ -126,6 +126,5 @@ BREAKING CHANGE: This has to be done because lorem ipsum dolor #### Pull Request Workflow Once you open a Pull Request, it may be reviewed or labeled (or both) until -the maintainers accept your change. Then, [bors](https://github.com/bors) will -run the test suite with your changes and if it's successful, automatically -merge it in! +the maintainers accept your change. Please be patient, it may take some time +for this to happen! From a6e86fc995f8e6555b80dc5e73b4d7d78c050706 Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 13:22:29 +0200 Subject: [PATCH 379/476] doc: update readme --- README.md | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 12a77810..103aec8b 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ Start-BitsTransfer -Source https://raw.githubusercontent.com/rust-lang/rustlings To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. -When you get a permission denied message then you have to exclude the directory where you placed the rustlings in your virus-scanner +If you get a permission denied message, you might have to exclude the directory where you cloned Rustlings in your antivirus. -## Browser: +## Browser [Run on Repl.it](https://repl.it/github/rust-lang/rustlings) @@ -150,24 +150,6 @@ cargo uninstall rustlings Now you should be done! -## Completion - -Rustlings isn't done; there are a couple of sections that are very experimental and don't have proper documentation. These include: - -- Errors (`exercises/errors/`) -- Option (`exercises/option/`) -- Result (`exercises/result/`) -- Move Semantics (could still be improved, `exercises/move_semantics/`) - -Additionally, we could use exercises on a couple of topics: - -- Structs -- Better ownership stuff -- `impl` -- ??? probably more - -If you are interested in improving or adding new ones, please feel free to contribute! Read on for more information :) - ## Contributing See [CONTRIBUTING.md](./CONTRIBUTING.md). From a3c4c1ccb4d7de6638b296387607c0a44b10e11f Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 13:24:11 +0200 Subject: [PATCH 380/476] fix: re-add missing done comments --- exercises/clippy/clippy3.rs | 2 ++ exercises/quiz2.rs | 2 ++ exercises/strings/strings3.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/exercises/clippy/clippy3.rs b/exercises/clippy/clippy3.rs index 13733c0b..b0159ebe 100644 --- a/exercises/clippy/clippy3.rs +++ b/exercises/clippy/clippy3.rs @@ -1,6 +1,8 @@ // clippy3.rs // Here's a couple more easy Clippy fixes, so you can see its utility. +// I AM NOT DONE + #[allow(unused_variables, unused_assignments)] fn main() { let my_option: Option<()> = None; diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index 5d3ccc03..f7437fd2 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -18,6 +18,8 @@ // - The output element is going to be a Vector of strings. // Execute `rustlings hint quiz2` or use the `hint` watch subcommand for a hint. +// I AM NOT DONE + pub enum Command { Uppercase, Trim, diff --git a/exercises/strings/strings3.rs b/exercises/strings/strings3.rs index bb0a259e..9e25d307 100644 --- a/exercises/strings/strings3.rs +++ b/exercises/strings/strings3.rs @@ -1,6 +1,8 @@ // strings3.rs // Execute `rustlings hint strings3` or use the `hint` watch subcommand for a hint. +// I AM NOT DONE + fn trim_me(input: &str) -> String { // TODO: Remove whitespace from the end of a string! ??? From a3b5278b4259da83bad1f645e19ba6b0d36f4dde Mon Sep 17 00:00:00 2001 From: exdx Date: Fri, 15 Jul 2022 13:28:49 +0200 Subject: [PATCH 381/476] feat: add threads3.rs exercise --- exercises/threads/threads3.rs | 64 +++++++++++++++++++++++++++++++++++ info.toml | 14 ++++++++ 2 files changed, 78 insertions(+) create mode 100644 exercises/threads/threads3.rs diff --git a/exercises/threads/threads3.rs b/exercises/threads/threads3.rs new file mode 100644 index 00000000..27e99088 --- /dev/null +++ b/exercises/threads/threads3.rs @@ -0,0 +1,64 @@ +// threads3.rs +// Execute `rustlings hint threads3` or use the `hint` watch subcommand for a hint. + +// I AM NOT DONE + +use std::sync::mpsc; +use std::sync::Arc; +use std::thread; +use std::time::Duration; + +struct Queue { + length: u32, + first_half: Vec, + second_half: Vec, +} + +impl Queue { + fn new() -> Self { + Queue { + length: 10, + first_half: vec![1, 2, 3, 4, 5], + second_half: vec![6, 7, 8, 9, 10], + } + } +} + +fn send_tx(q: Queue, tx: mpsc::Sender) -> () { + let qc = Arc::new(q); + let qc1 = qc.clone(); + let qc2 = qc.clone(); + + thread::spawn(move || { + for val in &qc1.first_half { + println!("sending {:?}", val); + tx.send(*val).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); + + thread::spawn(move || { + for val in &qc2.second_half { + println!("sending {:?}", val); + tx.send(*val).unwrap(); + thread::sleep(Duration::from_secs(1)); + } + }); +} + +fn main() { + let (tx, rx) = mpsc::channel(); + let queue = Queue::new(); + let queue_length = queue.length; + + send_tx(queue, tx); + + let mut total_received: u32 = 0; + for received in rx { + println!("Got: {}", received); + total_received += 1; + } + + println!("total numbers received: {}", total_received); + assert_eq!(total_received, queue_length) +} diff --git a/info.toml b/info.toml index c239121d..8871c15b 100644 --- a/info.toml +++ b/info.toml @@ -918,6 +918,20 @@ If you've learned from the sample solutions, I encourage you to come back to this exercise and try it again in a few days to reinforce what you've learned :)""" +[[exercises]] +name = "threads3" +path = "exercises/threads/threads3.rs" +mode = "compile" +hint = """ +An alternate way to handle concurrency between threads is to use +a mpsc (multiple producer, single consumer) channel to communicate. +With both a sending end and a receiving end, it's possible to +send values in one thread and receieve them in another. +Multiple producers are possibile by using clone() to create a duplicate +of the original sending end. +See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. +""" + # MACROS [[exercises]] From b71429bef03158398dafc3e537fa6db1495622ff Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:29:44 +0000 Subject: [PATCH 382/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 53044946..2bafe713 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -189,6 +189,9 @@ authors.
Paulo Gabriel Justino Bezerra

🖋
Jason

🖋 + +
exdx

🖋 + From c9332062ce3687905638c681140ad5d57ea162d8 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:29:45 +0000 Subject: [PATCH 383/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7bdfe974..523aff2d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1326,6 +1326,15 @@ "contributions": [ "content" ] + }, + { + "login": "exdx", + "name": "exdx", + "avatar_url": "https://avatars.githubusercontent.com/u/31546601?v=4", + "profile": "https://exdx.github.io", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 1cc5df0e144ef3551062c162e2e1618c27d97ae0 Mon Sep 17 00:00:00 2001 From: James Zow Date: Fri, 15 Jul 2022 13:46:03 +0200 Subject: [PATCH 384/476] feat: add github actions config --- .github/workflows/rust.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 00000000..bf2a041a --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,20 @@ +name: Rustlings Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose From bda4d548b4b4684be39153d3a6d63c047159167f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:49:08 +0000 Subject: [PATCH 385/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 2bafe713..3f687161 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -191,6 +191,7 @@ authors.
exdx

🖋 +
James Zow

🖋 From 9329c51df0d2abc766a8fefc1eaac255d66370e9 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 11:49:09 +0000 Subject: [PATCH 386/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 523aff2d..c0097f7f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1335,6 +1335,15 @@ "contributions": [ "content" ] + }, + { + "login": "Jzow", + "name": "James Zow", + "avatar_url": "https://avatars.githubusercontent.com/u/68860495?v=4", + "profile": "https://github.com/Jzow", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 1ef8dacaf69e3ad1418355eeea128c00f09bdcb3 Mon Sep 17 00:00:00 2001 From: jayber Date: Fri, 15 Jul 2022 14:01:32 +0200 Subject: [PATCH 387/476] feat: add lifetimes exercises --- exercises/lifetimes/README.md | 17 +++++++++++++++++ exercises/lifetimes/lifetimes1.rs | 26 ++++++++++++++++++++++++++ exercises/lifetimes/lifetimes2.rs | 27 +++++++++++++++++++++++++++ exercises/lifetimes/lifetimes3.rs | 20 ++++++++++++++++++++ info.toml | 24 ++++++++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 exercises/lifetimes/README.md create mode 100644 exercises/lifetimes/lifetimes1.rs create mode 100644 exercises/lifetimes/lifetimes2.rs create mode 100644 exercises/lifetimes/lifetimes3.rs diff --git a/exercises/lifetimes/README.md b/exercises/lifetimes/README.md new file mode 100644 index 00000000..72befb3e --- /dev/null +++ b/exercises/lifetimes/README.md @@ -0,0 +1,17 @@ +# Lifetimes + +Lifetimes tell the compiler how to check whether references live long +enough to be valid in any given situation. For example lifetimes say +"make sure parameter 'a' lives as long as parameter 'b' so that the return +value is valid". + +They are only necessary on borrows, i.e. references, +since copied parameters or moves are owned in their scope and cannot +be referenced outside. Lifetimes mean that calling code of e.g. functions +can be checked to make sure their arguments are valid. Lifetimes are +restrictive of their callers. + +## Further information + +- [Validating References with Lifetimes](https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html) +- [Lifetimes (in Rust By Example)](https://doc.rust-lang.org/stable/rust-by-example/scope/lifetime.html) diff --git a/exercises/lifetimes/lifetimes1.rs b/exercises/lifetimes/lifetimes1.rs new file mode 100644 index 00000000..58e995c6 --- /dev/null +++ b/exercises/lifetimes/lifetimes1.rs @@ -0,0 +1,26 @@ +// lifetimes1.rs +// +// The Rust compiler needs to know how to check whether supplied references are +// valid, so that it can let the programmer know if a reference is at risk +// of going out of scope before it is used. Remember, references are borrows +// and do not own their own data. What if their owner goes out of scope? +// +// Execute `rustlings hint lifetimes1` or use the `hint` watch subcommand for a hint. + +// I AM NOT DONE + +fn longest(x: &str, y: &str) -> &str { + if x.len() > y.len() { + x + } else { + y + } +} + +fn main() { + let string1 = String::from("abcd"); + let string2 = "xyz"; + + let result = longest(string1.as_str(), string2); + println!("The longest string is {}", result); +} diff --git a/exercises/lifetimes/lifetimes2.rs b/exercises/lifetimes/lifetimes2.rs new file mode 100644 index 00000000..c73a28ad --- /dev/null +++ b/exercises/lifetimes/lifetimes2.rs @@ -0,0 +1,27 @@ +// lifetimes2.rs +// +// So if the compiler is just validating the references passed +// to the annotated parameters and the return type, what do +// we need to change? +// +// Execute `rustlings hint lifetimes2` or use the `hint` watch subcommand for a hint. + +// I AM NOT DONE + +fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { + if x.len() > y.len() { + x + } else { + y + } +} + +fn main() { + let string1 = String::from("long string is long"); + let result; + { + let string2 = String::from("xyz"); + result = longest(string1.as_str(), string2.as_str()); + } + println!("The longest string is {}", result); +} diff --git a/exercises/lifetimes/lifetimes3.rs b/exercises/lifetimes/lifetimes3.rs new file mode 100644 index 00000000..ea483708 --- /dev/null +++ b/exercises/lifetimes/lifetimes3.rs @@ -0,0 +1,20 @@ +// lifetimes3.rs +// +// Lifetimes are also needed when structs hold references. +// +// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a hint. + +// I AM NOT DONE + +struct Book { + author: &str, + title: &str, +} + +fn main() { + let name = String::from("Jill Smith"); + let title = String::from("Fish Flying"); + let book = Book { author: &name, title: &title }; + + println!("{} by {}", book.title, book.author); +} diff --git a/info.toml b/info.toml index 8871c15b..bc2a91c9 100644 --- a/info.toml +++ b/info.toml @@ -746,6 +746,30 @@ You can call a function right where you're passing arguments to `assert!` -- so something like `assert!(having_fun())`. If you want to check that you indeed get false, you can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" +# LIFETIMES + +[[exercises]] +name = "lifetimes1" +path = "exercises/lifetimes/lifetimes1.rs" +mode = "compile" +hint = """ +Let the compiler guide you. Also take a look at the book if you need help: +https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html""" + +[[exercises]] +name = "lifetimes2" +path = "exercises/lifetimes/lifetimes2.rs" +mode = "compile" +hint = """ +What is the compiler checking? How could you change how long an owned variable lives?""" + +[[exercises]] +name = "lifetimes3" +path = "exercises/lifetimes/lifetimes3.rs" +mode = "compile" +hint = """ +If you use a lifetime annotation in a struct's fields, where else does it need to be added?""" + # STANDARD LIBRARY TYPES [[exercises]] From 75ba60bda652d29a58c46b4404dcf53dd6cbe691 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:05:35 +0000 Subject: [PATCH 388/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 3f687161..a6451709 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -192,6 +192,7 @@ authors.
exdx

🖋
James Zow

🖋 +
James Bromley

🖋 From 2427184017cea2008277ccaf4da362e308a9ab88 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:05:36 +0000 Subject: [PATCH 389/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c0097f7f..b9802601 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1344,6 +1344,15 @@ "contributions": [ "content" ] + }, + { + "login": "jayber", + "name": "James Bromley", + "avatar_url": "https://avatars.githubusercontent.com/u/2474334?v=4", + "profile": "https://jamesabromley.wordpress.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 9b66b2a0e981269c0b22e3b5b4057fb4c45fbba1 Mon Sep 17 00:00:00 2001 From: Rod Elias Date: Fri, 15 Jul 2022 14:08:51 +0200 Subject: [PATCH 390/476] fix(try_from_into): fix function name --- exercises/conversions/try_from_into.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index bc71a3c3..fa98bc90 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -56,7 +56,7 @@ impl TryFrom<&[i16]> for Color { } fn main() { - // Use the `from` function + // Use the `try_from` function let c1 = Color::try_from((183, 65, 14)); println!("{:?}", c1); From f43c6d78770ac90725490344dad98b9d3c076484 Mon Sep 17 00:00:00 2001 From: Sam White Date: Fri, 25 Feb 2022 16:40:38 +0000 Subject: [PATCH 391/476] feat: Add traits3.rs exercise --- exercises/traits/traits3.rs | 40 +++++++++++++++++++++++++++++++++++++ info.toml | 12 +++++++++++ 2 files changed, 52 insertions(+) create mode 100644 exercises/traits/traits3.rs diff --git a/exercises/traits/traits3.rs b/exercises/traits/traits3.rs new file mode 100644 index 00000000..917ded70 --- /dev/null +++ b/exercises/traits/traits3.rs @@ -0,0 +1,40 @@ +// traits3.rs +// +// Your task is to implement the Licensed trait for +// both structures and have them return the same +// information without writing the same function twice. +// +// Consider what you can add to the Licensed trait. + +// I AM NOT DONE + +pub trait Licensed { + fn licensing_info(&self) -> String; +} + +struct SomeSoftware { + version_number: i32, +} + +struct OtherSoftware { + version_number: String, +} + +impl Licensed for SomeSoftware {} // Don't edit this line +impl Licensed for OtherSoftware {} // Don't edit this line + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn is_licensing_info_the_same() { + let licensing_info = String::from("Some information"); + let some_software = SomeSoftware { version_number: 1 }; + let other_software = OtherSoftware { + version_number: "v2.0.0".to_string(), + }; + assert_eq!(some_software.licensing_info(), licensing_info); + assert_eq!(other_software.licensing_info(), licensing_info); + } +} diff --git a/info.toml b/info.toml index bc2a91c9..971f5155 100644 --- a/info.toml +++ b/info.toml @@ -704,6 +704,18 @@ what the result should look like! Vectors provide suitable methods for adding an element at the end. See the documentation at: https://doc.rust-lang.org/std/vec/struct.Vec.html""" +[[exercises]] +name = "traits3" +path = "exercises/traits/traits3.rs" +mode = "test" +hint = """ +Traits can have a default implementation for functions. Structs that implement +the trait can then use the default version of these functions if they choose not +implement the function themselves. + +See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations +""" + # QUIZ 3 [[exercises]] From 599d634ee2277d1071dd803346993c24ab13462b Mon Sep 17 00:00:00 2001 From: Sam White Date: Fri, 25 Feb 2022 16:41:10 +0000 Subject: [PATCH 392/476] feat: Add traits4.rs exercise --- exercises/traits/traits4.rs | 44 +++++++++++++++++++++++++++++++++++++ info.toml | 11 ++++++++++ 2 files changed, 55 insertions(+) create mode 100644 exercises/traits/traits4.rs diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs new file mode 100644 index 00000000..cc5fe168 --- /dev/null +++ b/exercises/traits/traits4.rs @@ -0,0 +1,44 @@ +// traits4.rs +// +// Your task is to replace the '??' sections so the code compiles. +// Don't change any line other than 21. + +// I AM NOT DONE + +pub trait Licensed { + fn licensing_info(&self) -> String { + "some information".to_string() + } +} + +struct SomeSoftware {} + +struct OtherSoftware {} + +impl Licensed for SomeSoftware {} +impl Licensed for OtherSoftware {} + +fn compare_license_types(software: ??, software_two: ??) -> bool { + software.licensing_info() == software_two.licensing_info() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn compare_license_information() { + let some_software = SomeSoftware {}; + let other_software = OtherSoftware {}; + + assert!(compare_license_types(some_software, other_software)); + } + + #[test] + fn compare_license_information_backwards() { + let some_software = SomeSoftware {}; + let other_software = OtherSoftware {}; + + assert!(compare_license_types(other_software, some_software)); + } +} diff --git a/info.toml b/info.toml index 971f5155..2ad9a0eb 100644 --- a/info.toml +++ b/info.toml @@ -716,6 +716,17 @@ implement the function themselves. See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#default-implementations """ +[[exercises]] +name = "traits4" +path = "exercises/traits/traits4.rs" +mode = "test" +hint = """ +Instead of using concrete types as parameters you can use traits. Try replacing the +'??' with 'impl ' + +See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters +""" + # QUIZ 3 [[exercises]] From 63b0c7e399ad11246bf5bf3acac4517f67c890da Mon Sep 17 00:00:00 2001 From: Sam White Date: Fri, 25 Feb 2022 16:41:36 +0000 Subject: [PATCH 393/476] feat: add traits5.rs exercise --- exercises/traits/traits5.rs | 31 +++++++++++++++++++++++++++++++ info.toml | 11 +++++++++++ 2 files changed, 42 insertions(+) create mode 100644 exercises/traits/traits5.rs diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs new file mode 100644 index 00000000..ed2afb1e --- /dev/null +++ b/exercises/traits/traits5.rs @@ -0,0 +1,31 @@ +// traits5.rs +// +// Your task is to replace the '??' sections so the code compiles. +// Don't change any line other than 27. + +// I AM NOT DONE + +pub trait SomeTrait { + fn some_function(&self) -> bool { + true + } +} + +pub trait OtherTrait { + fn other_function(&self) -> bool { + true + } +} + +struct SomeStruct { + name: String, +} + +impl SomeTrait for SomeStruct {} +impl OtherTrait for SomeStruct {} + +fn some_func(item: ??) -> bool { + item.some_function() && item.other_function() +} + +fn main() {} diff --git a/info.toml b/info.toml index 2ad9a0eb..5b7b9b43 100644 --- a/info.toml +++ b/info.toml @@ -727,6 +727,17 @@ Instead of using concrete types as parameters you can use traits. Try replacing See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters """ +[[exercises]] +name = "traits5" +path = "exercises/traits/traits5.rs" +mode = "compile" +hint = """ +To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the +'??' with 'impl <> + <>'. + +See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax +""" + # QUIZ 3 [[exercises]] From 1a7a3f5c8e4544873d25ec5338dbdf366aba9f8a Mon Sep 17 00:00:00 2001 From: mokou Date: Fri, 15 Jul 2022 14:14:48 +0200 Subject: [PATCH 394/476] fix(traits): update hint comments --- exercises/traits/traits3.rs | 1 + exercises/traits/traits4.rs | 1 + exercises/traits/traits5.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/exercises/traits/traits3.rs b/exercises/traits/traits3.rs index 917ded70..6d2fd6c3 100644 --- a/exercises/traits/traits3.rs +++ b/exercises/traits/traits3.rs @@ -5,6 +5,7 @@ // information without writing the same function twice. // // Consider what you can add to the Licensed trait. +// Execute `rustlings hint traits3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs index cc5fe168..280aaade 100644 --- a/exercises/traits/traits4.rs +++ b/exercises/traits/traits4.rs @@ -2,6 +2,7 @@ // // Your task is to replace the '??' sections so the code compiles. // Don't change any line other than 21. +// Execute `rustlings hint traits4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs index ed2afb1e..290c0479 100644 --- a/exercises/traits/traits5.rs +++ b/exercises/traits/traits5.rs @@ -2,6 +2,7 @@ // // Your task is to replace the '??' sections so the code compiles. // Don't change any line other than 27. +// Execute `rustlings hint traits5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE From 2b349e3b28d4d3aac2ba4c82590e64edfeb4217c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:15:56 +0000 Subject: [PATCH 395/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index a6451709..f8de046d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -193,6 +193,7 @@ authors.
exdx

🖋
James Zow

🖋
James Bromley

🖋 +
swhiteCQC

🖋 From 211528c31b08b727a955e0996d9a895f806d1097 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:15:57 +0000 Subject: [PATCH 396/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b9802601..0c612452 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1353,6 +1353,15 @@ "contributions": [ "content" ] + }, + { + "login": "swhiteCQC", + "name": "swhiteCQC", + "avatar_url": "https://avatars.githubusercontent.com/u/77438466?v=4", + "profile": "https://github.com/swhiteCQC", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From c265b681b188ea21b3f8585e65ea363fc02c4b50 Mon Sep 17 00:00:00 2001 From: Neil Pate Date: Fri, 15 Jul 2022 14:18:31 +0200 Subject: [PATCH 397/476] fix(quiz1): change function name --- exercises/quiz1.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 7bd3f589..8d05b110 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -11,14 +11,14 @@ // I AM NOT DONE // Put your function here! -// fn calculate_apple_price { +// fn calculate_price_of_apples { // Don't modify this function! #[test] fn verify_test() { - let price1 = calculate_apple_price(35); - let price2 = calculate_apple_price(40); - let price3 = calculate_apple_price(65); + let price1 = calculate_price_of_apples(35); + let price2 = calculate_price_of_apples(40); + let price3 = calculate_price_of_apples(65); assert_eq!(70, price1); assert_eq!(80, price2); From bc253097634dddb116f4ef656531931d8f8074e7 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:19:26 +0000 Subject: [PATCH 398/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index f8de046d..1a0c167f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -194,6 +194,7 @@ authors.
James Zow

🖋
James Bromley

🖋
swhiteCQC

🖋 +
Neil Pate

🖋 From e36c95bb3a5a57821ea6b431c3d2304d4eb5ab5b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:19:27 +0000 Subject: [PATCH 399/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0c612452..bd4e3902 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1362,6 +1362,15 @@ "contributions": [ "content" ] + }, + { + "login": "neilpate", + "name": "Neil Pate", + "avatar_url": "https://avatars.githubusercontent.com/u/7802334?v=4", + "profile": "https://github.com/neilpate", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From cc3e1a851118b13ce3b2774d6437665b5aca0dc4 Mon Sep 17 00:00:00 2001 From: mokou Date: Sat, 16 Jul 2022 14:17:24 +0200 Subject: [PATCH 400/476] doc: update changelog --- CHANGELOG.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 095877b6..8aae3138 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,76 @@ + +## 5.0.0 (2022-07-16) + +#### Features + +- Hint comments in exercises now also include a reference to the + `hint` watch mode subcommand. +- **intro1**: Added more hints to point the user to the source file. +- **variables**: Switched variables3 and variables4. +- Moved `vec` and `primitive_types` exercises before `move_semantics`. +- Renamed `vec` to `vecs` to be more in line with the naming in general. +- Split up the `collections` exercises in their own folders. +- **vec2**: Added a second part of the function that provides an alternative, + immutable way of modifying vec values. +- **enums3**: Added a hint. +- Moved `strings` before `modules`. +- Added a `strings3` exercise to teach modifying strings. +- Added a `hashmaps3` exercise for some advanced usage of hashmaps. +- Moved the original `quiz2` to be `strings4`, since it only tested strings + anyways. +- Reworked `quiz2` into a new exercise that tests more chapters. +- Renamed `option` to `options`. +- **options1**: Rewrote parts of the exercise to remove the weird array + iteration stuff. +- Moved `generics3` to be `quiz3`. +- Moved box/arc exercises behind `iterators`. +- **iterators4**: Added a test for factorials of zero. +- Split `threads1` between two exercises, the first one focusing more on + `JoinHandle`s. +- Added a `threads3` exercises that uses `std::sync::mpsc`. +- Added a `clippy3` exercises with some more interesting checks. +- **as_ref_mut**: Added a section that actually tests `AsMut`. +- Added 3 new lifetimes exercises. +- Added 3 new traits exercises. + +#### Bug Fixes + +- **variables2**: Made output messages more verbose. +- **variables5**: Added a nudging hint about shadowing. +- **variables6**: Fixed link to book. +- **functions**: Clarified the README wording. Generally cleaned up + some hints and added some extra comments. +- **if2**: Renamed function name to `foo_if_fizz`. +- **move_semantics**: Clarified some hints. +- **quiz1**: Renamed the function name to be more verbose. +- **structs1**: Use an integer type instead of strings. Renamed "unit structs" + to "unit-like structs", as is used in the book. +- **structs3**: Added the `panic!` statement in from the beginning. +- **errors1**: Use `is_empty()` instead of `len() > 0` +- **errors3**: Improved the hint. +- **errors5**: Improved exercise instructions and the hint. +- **errors6**: Provided the skeleton of one of the functions that's supposed + to be implemented. +- **iterators3**: Inserted `todo!` into `divide()` to keep a compiler error + from happening. +- **from_str**: Added a hint comment about string error message conversion with + `Box`. +- **try_from_into**: Fixed the function name in comment. + +#### Removed + +- Removed the legacy LSP feature that was using `mod.rs` files. +- Removed `quiz4`. +- Removed `advanced_errs`. These were the last exercises in the recommended + order, and I've always felt like they didn't quite fit in with the mostly + simple, book-following style we've had in Rustlings. + +#### Housekeeping + +- Added missing exercises to the book index. +- Updated spacing in Cargo.toml. +- Added a GitHub actions config so that tests run on every PR/commit. + ## 4.8.0 (2022-07-01) From 5138f22e00137768054147b022f3f269190d3eb8 Mon Sep 17 00:00:00 2001 From: mokou Date: Sat, 16 Jul 2022 14:25:10 +0200 Subject: [PATCH 401/476] doc: update book links --- exercises/README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/exercises/README.md b/exercises/README.md index 2ea29909..e52137ca 100644 --- a/exercises/README.md +++ b/exercises/README.md @@ -5,20 +5,22 @@ | variables | §3.1 | | functions | §3.3 | | if | §3.5 | -| move_semantics | §4.1, §4.2 | | primitive_types | §3.2, §4.3 | +| vecs | §8.1 | +| move_semantics | §4.1, §4.2 | | structs | §5.1, §5.3 | | enums | §6, §18.3 | -| modules | §7 | -| collections | §8.1, §8.3 | | strings | §8.2 | +| modules | §7 | +| hashmaps | §8.3 | +| options | §10.1 | | error_handling | §9 | | generics | §10 | -| option | §10.1 | | traits | §10.2 | | tests | §11.1 | +| lifetimes | §10.3 | | standard_library_types | §13.2, §15.1, §16.3 | -| threads | §16.1 | +| threads | §16.1, §16.2, §16.3 | | macros | §19.6 | | clippy | n/a | | conversions | n/a | From 5435b8084177941c8cf86e17a8fccaf1cef359a4 Mon Sep 17 00:00:00 2001 From: mokou Date: Sat, 16 Jul 2022 14:30:04 +0200 Subject: [PATCH 402/476] chore: bump version --- Cargo.toml | 2 +- README.md | 4 ++-- src/main.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a3264d9..910b5389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "4.8.0" +version = "5.0.0" authors = ["Liv ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/README.md b/README.md index 103aec8b..f2387328 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ If you get a permission denied message, you might 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.7.1) -git clone -b 4.7.1 --depth 1 https://github.com/rust-lang/rustlings +# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.0.0) +git clone -b 5.0.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 15c3095e..0ddb7331 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "4.8.0"; +const VERSION: &str = "5.0.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From 55900c65cbcd88a8458ea5ba29e06c1897f344d5 Mon Sep 17 00:00:00 2001 From: wojexe <21208490+wojexe@users.noreply.github.com> Date: Sat, 16 Jul 2022 17:28:13 +0200 Subject: [PATCH 403/476] fix: make strings3.rs comment wording more clear fixes #1063 --- exercises/strings/strings3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/strings/strings3.rs b/exercises/strings/strings3.rs index 9e25d307..e2353aec 100644 --- a/exercises/strings/strings3.rs +++ b/exercises/strings/strings3.rs @@ -4,7 +4,7 @@ // I AM NOT DONE fn trim_me(input: &str) -> String { - // TODO: Remove whitespace from the end of a string! + // TODO: Remove whitespace from both ends of a string! ??? } From e8cf9b262882adc77dd15e958ae038882ee10719 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 16 Jul 2022 16:27:40 +0000 Subject: [PATCH 404/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 1a0c167f..ba75fe62 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -195,6 +195,7 @@ authors.
James Bromley

🖋
swhiteCQC

🖋
Neil Pate

🖋 +
wojexe

🖋 From 3bb008ebbb52a4ab24131918bb8809f1eeba8480 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 16 Jul 2022 16:27:41 +0000 Subject: [PATCH 405/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index bd4e3902..cc6939f4 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1371,6 +1371,15 @@ "contributions": [ "content" ] + }, + { + "login": "wojexe", + "name": "wojexe", + "avatar_url": "https://avatars.githubusercontent.com/u/21208490?v=4", + "profile": "https://wojexe.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From b0e070c743d1f9a4a4eeb5c33a1e9ded8ab9bc12 Mon Sep 17 00:00:00 2001 From: wojexe <21208490+wojexe@users.noreply.github.com> Date: Sat, 16 Jul 2022 19:51:50 +0200 Subject: [PATCH 406/476] fix(traits4.rs): wrong line number fixes #1067 --- exercises/traits/traits4.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/traits/traits4.rs b/exercises/traits/traits4.rs index 280aaade..6b541665 100644 --- a/exercises/traits/traits4.rs +++ b/exercises/traits/traits4.rs @@ -1,7 +1,7 @@ // traits4.rs // // Your task is to replace the '??' sections so the code compiles. -// Don't change any line other than 21. +// Don't change any line other than the marked one. // Execute `rustlings hint traits4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -19,6 +19,7 @@ struct OtherSoftware {} impl Licensed for SomeSoftware {} impl Licensed for OtherSoftware {} +// YOU MAY ONLY CHANGE THE NEXT LINE fn compare_license_types(software: ??, software_two: ??) -> bool { software.licensing_info() == software_two.licensing_info() } From ce86d252e529385704fe9111e305ac0ec48c2de4 Mon Sep 17 00:00:00 2001 From: Denton24646 Date: Sat, 16 Jul 2022 15:31:37 -0400 Subject: [PATCH 407/476] feat: add rc1.rs exercise --- exercises/standard_library_types/rc1.rs | 98 +++++++++++++++++++++++++ info.toml | 14 ++++ 2 files changed, 112 insertions(+) create mode 100644 exercises/standard_library_types/rc1.rs diff --git a/exercises/standard_library_types/rc1.rs b/exercises/standard_library_types/rc1.rs new file mode 100644 index 00000000..9b907fde --- /dev/null +++ b/exercises/standard_library_types/rc1.rs @@ -0,0 +1,98 @@ +// rc1.rs +// In this exercise, we want to express the concept of multiple owners via the Rc type. +// This is a model of our solar system - there is a Sun type and multiple Planets. +// The Planets take ownership of the sun, indicating that they revolve around the sun. + +// Make this code compile by using the proper Rc primitives to express that the sun has multiple owners. + +// I AM NOT DONE +use std::rc::Rc; + +#[derive(Debug)] +struct Sun {} + +#[derive(Debug)] +enum Planet { + Mercury(Rc), + Venus(Rc), + Earth(Rc), + Mars(Rc), + Jupiter(Rc), + Saturn(Rc), + Uranus(Rc), + Neptune(Rc), +} + +impl Planet { + fn details(&self) { + println!("Hi from {:?}!", self) + } +} + +fn main() { + let sun = Rc::new(Sun {}); + println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference + + let mercury = Planet::Mercury(Rc::clone(&sun)); + println!("reference count = {}", Rc::strong_count(&sun)); // 2 references + mercury.details(); + + let venus = Planet::Venus(Rc::clone(&sun)); + println!("reference count = {}", Rc::strong_count(&sun)); // 3 references + venus.details(); + + let earth = Planet::Earth(Rc::clone(&sun)); + println!("reference count = {}", Rc::strong_count(&sun)); // 4 references + earth.details(); + + let mars = Planet::Mars(Rc::clone(&sun)); + println!("reference count = {}", Rc::strong_count(&sun)); // 5 references + mars.details(); + + let jupiter = Planet::Jupiter(Rc::clone(&sun)); + println!("reference count = {}", Rc::strong_count(&sun)); // 6 references + jupiter.details(); + + // TODO + let saturn = Planet::Saturn(Rc::new(Sun {})); + println!("reference count = {}", Rc::strong_count(&sun)); // 7 references + saturn.details(); + + // TODO + let uranus = Planet::Uranus(Rc::new(Sun {})); + println!("reference count = {}", Rc::strong_count(&sun)); // 8 references + uranus.details(); + + // TODO + let neptune = Planet::Neptune(Rc::new(Sun {})); + println!("reference count = {}", Rc::strong_count(&sun)); // 9 references + neptune.details(); + + assert_eq!(Rc::strong_count(&sun), 9); + + drop(neptune); + println!("reference count = {}", Rc::strong_count(&sun)); // 8 references + + drop(uranus); + println!("reference count = {}", Rc::strong_count(&sun)); // 7 references + + drop(saturn); + println!("reference count = {}", Rc::strong_count(&sun)); // 6 references + + drop(jupiter); + println!("reference count = {}", Rc::strong_count(&sun)); // 5 references + + drop(mars); + println!("reference count = {}", Rc::strong_count(&sun)); // 4 references + + // TODO + println!("reference count = {}", Rc::strong_count(&sun)); // 3 references + + // TODO + println!("reference count = {}", Rc::strong_count(&sun)); // 2 references + + // TODO + println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference + + assert_eq!(Rc::strong_count(&sun), 1); +} diff --git a/info.toml b/info.toml index 5b7b9b43..a72c0147 100644 --- a/info.toml +++ b/info.toml @@ -929,6 +929,20 @@ is too much of a struggle, consider reading through all of Chapter 16 in the boo https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html """ +[[exercises]] +name = "rc1" +path = "exercises/standard_library_types/rc1.rs" +mode = "compile" +hint = """ +This is a straightforward exercise to use the Rc type. Each Planet has +ownership of the Sun, and uses Rc::clone() to increment the reference count of the Sun. +After using drop() to move the Planets out of scope individually, the reference count goes down. +In the end the sun only has one reference again, to itself. See more at: +https://doc.rust-lang.org/book/ch15-04-rc.html + +* Unforunately Pluto is no longer considered a planet :( +""" + # THREADS [[exercises]] From 7035d6787cd551ece7d582d052685c52875a6a72 Mon Sep 17 00:00:00 2001 From: Tostapunk Date: Mon, 18 Jul 2022 00:27:57 +0200 Subject: [PATCH 408/476] fix(traits5.rs): wrong line number --- exercises/traits/traits5.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs index 290c0479..89174dde 100644 --- a/exercises/traits/traits5.rs +++ b/exercises/traits/traits5.rs @@ -1,7 +1,7 @@ // traits5.rs // // Your task is to replace the '??' sections so the code compiles. -// Don't change any line other than 27. +// Don't change any line other than the marked one. // Execute `rustlings hint traits5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -25,6 +25,7 @@ struct SomeStruct { impl SomeTrait for SomeStruct {} impl OtherTrait for SomeStruct {} +// YOU MAY ONLY CHANGE THE NEXT LINE fn some_func(item: ??) -> bool { item.some_function() && item.other_function() } From 2f113b9b06b986d17c4da86ae5a5bd8a4405f83d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 08:47:49 +0000 Subject: [PATCH 409/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index ba75fe62..f015c8fd 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -196,6 +196,7 @@ authors.
swhiteCQC

🖋
Neil Pate

🖋
wojexe

🖋 +
Mattia Schiavon

🖋 From 1aecf32748fbccec18b044e91a533165bc52e226 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 18 Jul 2022 08:47:49 +0000 Subject: [PATCH 410/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index cc6939f4..9659044a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1380,6 +1380,15 @@ "contributions": [ "content" ] + }, + { + "login": "Tostapunk", + "name": "Mattia Schiavon", + "avatar_url": "https://avatars.githubusercontent.com/u/25140297?v=4", + "profile": "https://github.com/Tostapunk", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 02d78c3e84c8f160b6f6487be0a368b5720bb67b Mon Sep 17 00:00:00 2001 From: Tostapunk Date: Mon, 18 Jul 2022 14:11:51 +0200 Subject: [PATCH 411/476] fix: Improve hint of lifetimes2 fixes #1071 --- info.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 5b7b9b43..3ec15d7c 100644 --- a/info.toml +++ b/info.toml @@ -795,7 +795,10 @@ name = "lifetimes2" path = "exercises/lifetimes/lifetimes2.rs" mode = "compile" hint = """ -What is the compiler checking? How could you change how long an owned variable lives?""" +Remember that the generic lifetime 'a will get the concrete lifetime that is equal to the smaller of the lifetimes of x and y. +You can take at leats two paths to achieve the desidered result while keeping the inner block: +1. move string2 declaration to make it live as long as string1 (how is result declared?) +2. move println! into the inner block""" [[exercises]] name = "lifetimes3" From e1d6abb4c919386fd5c728a30db73d160c6fe373 Mon Sep 17 00:00:00 2001 From: Mattia Schiavon Date: Mon, 18 Jul 2022 14:44:16 +0200 Subject: [PATCH 412/476] Apply suggestions from code review Co-authored-by: liv --- info.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/info.toml b/info.toml index 3ec15d7c..0be3e91a 100644 --- a/info.toml +++ b/info.toml @@ -796,9 +796,9 @@ path = "exercises/lifetimes/lifetimes2.rs" mode = "compile" hint = """ Remember that the generic lifetime 'a will get the concrete lifetime that is equal to the smaller of the lifetimes of x and y. -You can take at leats two paths to achieve the desidered result while keeping the inner block: -1. move string2 declaration to make it live as long as string1 (how is result declared?) -2. move println! into the inner block""" +You can take at least two paths to achieve the desired result while keeping the inner block: +1. Move the string2 declaration to make it live as long as string1 (how is result declared?) +2. Move println! into the inner block""" [[exercises]] name = "lifetimes3" From 8a4dca5fa63913d42eddd443485f5a7c9d9f5319 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Tue, 19 Jul 2022 11:45:34 +0200 Subject: [PATCH 413/476] remove small typo in hint of threads3 --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 0be3e91a..f90d10a0 100644 --- a/info.toml +++ b/info.toml @@ -988,7 +988,7 @@ An alternate way to handle concurrency between threads is to use a mpsc (multiple producer, single consumer) channel to communicate. With both a sending end and a receiving end, it's possible to send values in one thread and receieve them in another. -Multiple producers are possibile by using clone() to create a duplicate +Multiple producers are possible by using clone() to create a duplicate of the original sending end. See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. """ From 3b74f5dae88f6097d2eb07694ec2bd0823db9c0a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:40:22 +0000 Subject: [PATCH 414/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index f015c8fd..ca763de2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -197,6 +197,7 @@ authors.
Neil Pate

🖋
wojexe

🖋
Mattia Schiavon

🖋 +
Eric Jolibois

🖋 From 82c41a61b6c6389244814a56ee272687bc8e262b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 19 Jul 2022 12:40:23 +0000 Subject: [PATCH 415/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 9659044a..3903233f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1389,6 +1389,15 @@ "contributions": [ "content" ] + }, + { + "login": "PrettyWood", + "name": "Eric Jolibois", + "avatar_url": "https://avatars.githubusercontent.com/u/18406791?v=4", + "profile": "http://toucantoco.com", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From f9413b8ae1c9fe8bd9ebed01f27450e8b98f233e Mon Sep 17 00:00:00 2001 From: Greg Leonard Date: Tue, 19 Jul 2022 20:05:04 +0100 Subject: [PATCH 416/476] fix(traits5): fix "paramter" spelling --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index f90d10a0..14031118 100644 --- a/info.toml +++ b/info.toml @@ -732,7 +732,7 @@ name = "traits5" path = "exercises/traits/traits5.rs" mode = "compile" hint = """ -To ensure a paramter implements multiple traits use the '+ syntax'. Try replacing the +To ensure a parameter implements multiple traits use the '+ syntax'. Try replacing the '??' with 'impl <> + <>'. See the documentation at: https://doc.rust-lang.org/book/ch10-02-traits.html#specifying-multiple-trait-bounds-with-the--syntax From f34d390bba3d60df0766df432bca9bc5eb171478 Mon Sep 17 00:00:00 2001 From: Edwin Chang Date: Wed, 20 Jul 2022 18:23:31 -0400 Subject: [PATCH 417/476] fix: Fix typo in .editorconfig --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 89cf181d..aab09aa3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,6 +2,6 @@ root = true [*.rs] end_of_line = lf -insert_final_newfile = true +insert_final_newline = true indent_style = space indent_size = 4 From e9f5c9423c8004fdccbe3dc300479497ed27c067 Mon Sep 17 00:00:00 2001 From: Greg Leonard Date: Thu, 21 Jul 2022 23:13:22 +0100 Subject: [PATCH 418/476] fix(run): correct "PAS" in `integration_tests.rs` --- tests/integration_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index fc46b983..0be191f0 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -176,7 +176,7 @@ fn run_single_test_success_with_output() { .current_dir("tests/fixture/success/") .assert() .code(0) - .stdout(predicates::str::contains("THIS TEST TOO SHALL PAS")); + .stdout(predicates::str::contains("THIS TEST TOO SHALL PASS")); } #[test] @@ -187,7 +187,7 @@ fn run_single_test_success_without_output() { .current_dir("tests/fixture/success/") .assert() .code(0) - .stdout(predicates::str::contains("THIS TEST TOO SHALL PAS").not()); + .stdout(predicates::str::contains("THIS TEST TOO SHALL PASS").not()); } #[test] From 2356b5c1b6a68cbcafb7643ba900adba4483d38a Mon Sep 17 00:00:00 2001 From: Saikat Das Date: Sat, 23 Jul 2022 15:55:30 +0530 Subject: [PATCH 419/476] Fix manual installation with install to the current directory --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2387328..afa55c86 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ If you get a permission denied message, you might have to exclude the directory ## Manually -Basically: Clone the repository at the latest tag, run `cargo install`. +Basically: Clone the repository at the latest tag, run `cargo install --path .`. ```bash # find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.0.0) From 56c05f6232a1cd4cfa5444b1d391f88feef98e7b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:37:05 +0000 Subject: [PATCH 420/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index ca763de2..27103bff 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -199,6 +199,9 @@ authors.
Mattia Schiavon

🖋
Eric Jolibois

🖋 + +
Edwin Chang

🖋 + From e858fd94fbed689b4533605ea133c8030a93197a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:37:06 +0000 Subject: [PATCH 421/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 3903233f..cd436694 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1398,6 +1398,15 @@ "contributions": [ "content" ] + }, + { + "login": "EdwinChang24", + "name": "Edwin Chang", + "avatar_url": "https://avatars.githubusercontent.com/u/88263098?v=4", + "profile": "http://edwinchang.vercel.app", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From c1fc77e50ffdca83f5f5cb03d28aef3c60bd76f2 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:41:02 +0000 Subject: [PATCH 422/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 27103bff..212bd602 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -201,6 +201,7 @@ authors.
Edwin Chang

🖋 +
Saikat Das

🖋 From 7a6079b46adb5e9c81e5c83ebce614b359a57239 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sat, 23 Jul 2022 15:41:03 +0000 Subject: [PATCH 423/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index cd436694..6450a9c6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1407,6 +1407,15 @@ "contributions": [ "content" ] + }, + { + "login": "saikatdas0790", + "name": "Saikat Das", + "avatar_url": "https://avatars.githubusercontent.com/u/7412443?v=4", + "profile": "https://saikat.dev/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From f88c7d1e8c89d26f5180082d68d4b79e4ec47b48 Mon Sep 17 00:00:00 2001 From: Jeremy Goh <30731072+thatlittleboy@users.noreply.github.com> Date: Sun, 24 Jul 2022 00:36:27 +0800 Subject: [PATCH 424/476] fix: reference to variables4 --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 14031118..7bb753ef 100644 --- a/info.toml +++ b/info.toml @@ -63,7 +63,7 @@ name = "variables5" path = "exercises/variables/variables5.rs" mode = "compile" hint = """ -In variables3 we already learned how to make an immutable variable mutable +In variables4 we already learned how to make an immutable variable mutable using a special keyword. Unfortunately this doesn't help us much in this exercise because we want to assign a different typed value to an existing variable. Sometimes you may also like to reuse existing variable names because you are just converting From 301bc52857554e047eabf32fec323f7a10e2b853 Mon Sep 17 00:00:00 2001 From: Jeremy Goh <30731072+thatlittleboy@users.noreply.github.com> Date: Sun, 24 Jul 2022 00:37:40 +0800 Subject: [PATCH 425/476] fix: lineno typo --- info.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.toml b/info.toml index 7bb753ef..f07b9267 100644 --- a/info.toml +++ b/info.toml @@ -123,8 +123,8 @@ name = "functions4" path = "exercises/functions/functions4.rs" mode = "compile" hint = """ -The error message points to line 14 and says it expects a type after the -`->`. This is where the function's return type should be-- take a look at +The error message points to line 17 and says it expects a type after the +`->`. This is where the function's return type should be -- take a look at the `is_even` function for an example! Also: Did you figure out that, technically, u32 would be the more fitting type From 72e21a2a6c2654cb1d2e292291e2e40914957776 Mon Sep 17 00:00:00 2001 From: Denton24646 Date: Sat, 23 Jul 2022 17:57:03 -0400 Subject: [PATCH 426/476] feat: add cow1.rs exercise --- exercises/standard_library_types/cow1.rs | 48 ++++++++++++++++++++++++ info.toml | 11 ++++++ 2 files changed, 59 insertions(+) create mode 100644 exercises/standard_library_types/cow1.rs diff --git a/exercises/standard_library_types/cow1.rs b/exercises/standard_library_types/cow1.rs new file mode 100644 index 00000000..5fba2519 --- /dev/null +++ b/exercises/standard_library_types/cow1.rs @@ -0,0 +1,48 @@ +// cow1.rs + +// This exercise explores the Cow, or Clone-On-Write type. +// Cow is a clone-on-write smart pointer. +// It can enclose and provide immutable access to borrowed data, and clone the data lazily when mutation or ownership is required. +// The type is designed to work with general borrowed data via the Borrow trait. + +// I AM NOT DONE + +use std::borrow::Cow; + +fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> { + for i in 0..input.len() { + let v = input[i]; + if v < 0 { + // Clones into a vector if not already owned. + input.to_mut()[i] = -v; + } + } + input +} + +fn main() { + // No clone occurs because `input` doesn't need to be mutated. + let slice = [0, 1, 2]; + let mut input = Cow::from(&slice[..]); + match abs_all(&mut input) { + Cow::Borrowed(_) => println!("I borrowed the slice!"), + _ => panic!("expected borrowed value"), + } + + // Clone occurs because `input` needs to be mutated. + let slice = [-1, 0, 1]; + let mut input = Cow::from(&slice[..]); + match abs_all(&mut input) { + Cow::Owned(_) => println!("I modified the slice and now own it!"), + _ => panic!("expected owned value"), + } + + // No clone occurs because `input` is already owned. + let slice = vec![-1, 0, 1]; + let mut input = Cow::from(slice); + match abs_all(&mut input) { + // TODO + Cow::Borrowed(_) => println!("I own this slice!"), + _ => panic!("expected borrowed value"), + } +} diff --git a/info.toml b/info.toml index 14031118..230fc724 100644 --- a/info.toml +++ b/info.toml @@ -932,6 +932,17 @@ is too much of a struggle, consider reading through all of Chapter 16 in the boo https://doc.rust-lang.org/stable/book/ch16-00-concurrency.html """ +[[exercises]] +name = "cow1" +path = "exercises/standard_library_types/cow1.rs" +mode = "compile" +hint = """ +Since the vector is already owned, the `Cow` type doesn't need to clone it. + +Checkout https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation +on the `Cow` type. +""" + # THREADS [[exercises]] From 32687cc66e04cc8b4975672847c7def48d9bb08a Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 24 Jul 2022 21:26:12 +0000 Subject: [PATCH 427/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 212bd602..ca641859 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -202,6 +202,7 @@ authors.
Edwin Chang

🖋
Saikat Das

🖋 +
Jeremy Goh

🖋 From 4bee3399f8be446c414cdad3c2c2a9983a3f3e35 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Sun, 24 Jul 2022 21:26:13 +0000 Subject: [PATCH 428/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6450a9c6..ae6156a6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1416,6 +1416,15 @@ "contributions": [ "content" ] + }, + { + "login": "thatlittleboy", + "name": "Jeremy Goh", + "avatar_url": "https://avatars.githubusercontent.com/u/30731072?v=4", + "profile": "https://github.com/thatlittleboy", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From a3a5fbeddf7ad891514a7cf4d51a582efdedb0f1 Mon Sep 17 00:00:00 2001 From: Claire Wang Date: Mon, 25 Jul 2022 17:54:09 -0700 Subject: [PATCH 429/476] fix: remove extra " typo in info.toml --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index f07b9267..dc1485d7 100644 --- a/info.toml +++ b/info.toml @@ -746,7 +746,7 @@ path = "exercises/quiz3.rs" mode = "test" hint = """ To find the best solution to this challenge you're going to need to think back to your -knowledge of traits, specifically Trait Bound Syntax - you may also need this: "use std::fmt::Display;"""" +knowledge of traits, specifically Trait Bound Syntax - you may also need this: `use std::fmt::Display;`.""" # TESTS From a56f648ccefc18292c2fbc2e61043348c7cde79d Mon Sep 17 00:00:00 2001 From: Tristan Nicholls Date: Tue, 26 Jul 2022 21:01:09 +0200 Subject: [PATCH 430/476] feat(options1): update expected result Expected result is updated to better showcase the difference between - a valid result with no ice-creams `Some(0)`, and - an invalid result `None`. --- exercises/options/options1.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index 038fb48e..c93ffbae 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -14,6 +14,7 @@ fn print_number(maybe_number: Option) { // TODO: Return an Option! fn maybe_icecream(time_of_day: u16) -> Option { // We use the 24-hour system here, so 10PM is a value of 22 + // The Option output should gracefully handle cases where time_of_day > 24. ??? } @@ -24,8 +25,9 @@ mod tests { #[test] fn check_icecream() { assert_eq!(maybe_icecream(10), Some(5)); - assert_eq!(maybe_icecream(23), None); - assert_eq!(maybe_icecream(22), None); + assert_eq!(maybe_icecream(23), Some(0)); + assert_eq!(maybe_icecream(22), Some(0)); + assert_eq!(maybe_icecream(25), None); } #[test] From c5ecc37a9afd8eaad3b184d97a0e532eef163b41 Mon Sep 17 00:00:00 2001 From: Lioness100 Date: Sat, 30 Jul 2022 10:50:07 -0400 Subject: [PATCH 431/476] refactor(box1): prefer todo! over unimplemented! --- exercises/standard_library_types/box1.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/standard_library_types/box1.rs b/exercises/standard_library_types/box1.rs index 9d9237c1..66cf00f3 100644 --- a/exercises/standard_library_types/box1.rs +++ b/exercises/standard_library_types/box1.rs @@ -10,7 +10,7 @@ // elements: the value of the current item and the next item. The last item is a value called `Nil`. // // Step 1: use a `Box` in the enum definition to make the code compile -// Step 2: create both empty and non-empty cons lists by replacing `unimplemented!()` +// Step 2: create both empty and non-empty cons lists by replacing `todo!()` // // Note: the tests should not be changed // @@ -33,11 +33,11 @@ fn main() { } pub fn create_empty_list() -> List { - unimplemented!() + todo!() } pub fn create_non_empty_list() -> List { - unimplemented!() + todo!() } #[cfg(test)] From a04d62372fcf6023fceb0f2e8202de61ca774585 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:13:18 +0000 Subject: [PATCH 432/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index ca641859..e6f7a35e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -203,6 +203,7 @@ authors.
Edwin Chang

🖋
Saikat Das

🖋
Jeremy Goh

🖋 +
Lioness100

🖋 From 08f42761f9b04dd63ac30ae3a503577ded560f3f Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:13:19 +0000 Subject: [PATCH 433/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index ae6156a6..7d6ec037 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1425,6 +1425,15 @@ "contributions": [ "content" ] + }, + { + "login": "Lioness100", + "name": "Lioness100", + "avatar_url": "https://avatars.githubusercontent.com/u/65814829?v=4", + "profile": "https://github.com/Lioness100", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From af301a2efe7309b3a59df4f236322eb246140402 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 3 Aug 2022 17:31:42 +0200 Subject: [PATCH 434/476] feat(errors5): add simpler explanation for box dyn --- Cargo.lock | 2 +- exercises/error_handling/errors5.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index df190ad8..862a8a2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.8.0" +version = "5.0.0" dependencies = [ "argh", "assert_cmd", diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 67411c58..2ba8f903 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -4,6 +4,8 @@ // 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. +// For now, think of the `Box` type as an "I want anything that does ???" type, which, given +// Rust's usual standards for runtime safety, should strike you as somewhat lenient! // In short, this particular use case for boxes is for when you want to own a value and you care only that it is a // type which implements a particular trait. To do so, The Box is declared as of type Box where Trait is the trait From e3b65186fde9690180a0efe9283f466a2e13076d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:34:59 +0000 Subject: [PATCH 435/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index e6f7a35e..263bc2f8 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -204,6 +204,7 @@ authors.
Saikat Das

🖋
Jeremy Goh

🖋
Lioness100

🖋 +
Tristan Nicholls

🖋 From 6289238d1d35d13fe44d7385ebe0016519db7adc Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:35:00 +0000 Subject: [PATCH 436/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7d6ec037..5ff2c661 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1434,6 +1434,15 @@ "contributions": [ "content" ] + }, + { + "login": "tvkn", + "name": "Tristan Nicholls", + "avatar_url": "https://avatars.githubusercontent.com/u/79277926?v=4", + "profile": "https://github.com/tvkn", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d27c12e35d7a1290ad1daccfe69e309da765e810 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:36:07 +0000 Subject: [PATCH 437/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 263bc2f8..e0689dbf 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -205,6 +205,7 @@ authors.
Jeremy Goh

🖋
Lioness100

🖋
Tristan Nicholls

🖋 +
Claire

🖋 From 7a7281764c03beb3560e7dba8759bcb7eab71f99 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:36:08 +0000 Subject: [PATCH 438/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5ff2c661..5fc58e7b 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1443,6 +1443,15 @@ "contributions": [ "content" ] + }, + { + "login": "clairew", + "name": "Claire", + "avatar_url": "https://avatars.githubusercontent.com/u/9344258?v=4", + "profile": "http://clairewang.net", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From a0a06232ce30ff7ec52367033865cad9cac6ae76 Mon Sep 17 00:00:00 2001 From: John Mendelewski III Date: Sun, 7 Aug 2022 14:51:16 -0400 Subject: [PATCH 439/476] fix(traits5): make exercise prefer trait-based solution closes #1088 --- exercises/traits/traits5.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/exercises/traits/traits5.rs b/exercises/traits/traits5.rs index 89174dde..0fbca28a 100644 --- a/exercises/traits/traits5.rs +++ b/exercises/traits/traits5.rs @@ -18,16 +18,20 @@ pub trait OtherTrait { } } -struct SomeStruct { - name: String, -} +struct SomeStruct {} +struct OtherStruct {} impl SomeTrait for SomeStruct {} impl OtherTrait for SomeStruct {} +impl SomeTrait for OtherStruct {} +impl OtherTrait for OtherStruct {} // YOU MAY ONLY CHANGE THE NEXT LINE fn some_func(item: ??) -> bool { item.some_function() && item.other_function() } -fn main() {} +fn main() { + some_func(SomeStruct {}); + some_func(OtherStruct {}); +} From f25f77e915035dc913f680593bc4892e5f8edeaf Mon Sep 17 00:00:00 2001 From: Brian Fakhoury Date: Mon, 8 Aug 2022 15:39:35 -0400 Subject: [PATCH 440/476] Fix minor spelling --- exercises/quiz2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index f7437fd2..d8fa954a 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -42,7 +42,7 @@ mod my_module { #[cfg(test)] mod tests { - // TODO: What to we have to import to have `transformer` in scope? + // TODO: What do we have to import to have `transformer` in scope? use ???; use super::Command; From ef70ad907f4615b34abe3e65c7b21fffe7661f35 Mon Sep 17 00:00:00 2001 From: Mouwrice Date: Tue, 9 Aug 2022 20:27:27 +0200 Subject: [PATCH 441/476] fix(macros-readme): update the book link to the more recent version of the book --- exercises/macros/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/macros/README.md b/exercises/macros/README.md index 319d8408..31a941b7 100644 --- a/exercises/macros/README.md +++ b/exercises/macros/README.md @@ -7,4 +7,4 @@ macros. Instead, we'll show you how to use and create them. ## Further information - [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html) -- [The Little Book of Rust Macros](https://danielkeep.github.io/tlborm/book/index.html) +- [The Little Book of Rust Macros](https://veykril.github.io/tlborm/) From bf84fe029f05e05c65efaaaa36f04cf6ed19235b Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:27:27 +0000 Subject: [PATCH 442/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index e0689dbf..66f4b9e2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -206,6 +206,7 @@ authors.
Lioness100

🖋
Tristan Nicholls

🖋
Claire

🖋 +
Maurice Van Wassenhove

🖋 From 8d9df94b6c6682d607976001f16cba851f5979a9 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:27:28 +0000 Subject: [PATCH 443/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5fc58e7b..d97c45fb 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1452,6 +1452,15 @@ "contributions": [ "content" ] + }, + { + "login": "Mouwrice", + "name": "Maurice Van Wassenhove", + "avatar_url": "https://avatars.githubusercontent.com/u/56763273?v=4", + "profile": "https://github.com/Mouwrice", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From dcf4efe62851823c31ea78b929b4450de86fecfe Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:30:24 +0000 Subject: [PATCH 444/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 66f4b9e2..6dcbbeee 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -207,6 +207,7 @@ authors.
Tristan Nicholls

🖋
Claire

🖋
Maurice Van Wassenhove

🖋 +
John Mendelewski

💻 From c1c4f863172bf36ce6822e05d210bc2d82fdcbce Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:30:25 +0000 Subject: [PATCH 445/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index d97c45fb..4133fc21 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1461,6 +1461,15 @@ "contributions": [ "content" ] + }, + { + "login": "johnmendel", + "name": "John Mendelewski", + "avatar_url": "https://avatars.githubusercontent.com/u/77524?v=4", + "profile": "http://jmthree.com", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From 7e1a4c03637f38ff8f380652c26fcfee637fe47c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:38:00 +0000 Subject: [PATCH 446/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 6dcbbeee..613a2c0d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -209,6 +209,9 @@ authors.
Maurice Van Wassenhove

🖋
John Mendelewski

💻 + +
Brian Fakhoury

🖋 + From a16e7b918a1ce3e257f39db6182289cad047748c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:38:01 +0000 Subject: [PATCH 447/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 4133fc21..87af2a52 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1470,6 +1470,15 @@ "contributions": [ "code" ] + }, + { + "login": "brianfakhoury", + "name": "Brian Fakhoury", + "avatar_url": "https://avatars.githubusercontent.com/u/20828724?v=4", + "profile": "http://fakhoury.xyz", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 3c84cc1702200eea4d3e57feff34e69705dc8ed1 Mon Sep 17 00:00:00 2001 From: Markus Boehme Date: Thu, 11 Aug 2022 22:52:06 +0200 Subject: [PATCH 448/476] fix(options1): remove unused code Since rewriting the exercise in commit 06e4fd376586 the print_number function goes unused. Remove it. --- exercises/options/options1.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index c93ffbae..99c95911 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -3,11 +3,6 @@ // I AM NOT DONE -// you can modify anything EXCEPT for this function's signature -fn print_number(maybe_number: Option) { - println!("printing: {}", maybe_number.unwrap()); -} - // This function returns how much icecream there is left in the fridge. // If it's before 10PM, there's 5 pieces left. At 10PM, someone eats them // all, so there'll be no more left :( From cf813b707cf9ef0593ae58853eb693594c5fc03c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Aug 2022 08:25:12 +0000 Subject: [PATCH 449/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 613a2c0d..9648f33c 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -211,6 +211,7 @@ authors.
Brian Fakhoury

🖋 +
Markus Boehme

💻 From f107e2f31d961b949868967cd2f66dc78136411c Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Aug 2022 08:25:13 +0000 Subject: [PATCH 450/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 87af2a52..0df89f7e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1479,6 +1479,15 @@ "contributions": [ "content" ] + }, + { + "login": "markusboehme", + "name": "Markus Boehme", + "avatar_url": "https://avatars.githubusercontent.com/u/5074759?v=4", + "profile": "https://github.com/markusboehme", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 8, From e8122daa8709274226c40fe8008fdfc86ad4493a Mon Sep 17 00:00:00 2001 From: Nico Vromans <48183857+nico-vromans@users.noreply.github.com> Date: Mon, 15 Aug 2022 10:05:50 +0200 Subject: [PATCH 451/476] Update options1.rs Added extra test for before 10PM and updated the test for at 10PM (when it's 10PM there should already not be any ice cream left, as per the description). Also fixed the `raw_value` test, as it is later than 10PM, so there should be no more ice cream left. --- exercises/options/options1.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index 99c95911..022d3d66 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -19,7 +19,8 @@ mod tests { #[test] fn check_icecream() { - assert_eq!(maybe_icecream(10), Some(5)); + assert_eq!(maybe_icecream(9), Some(5)); + assert_eq!(maybe_icecream(10), Some(0)); assert_eq!(maybe_icecream(23), Some(0)); assert_eq!(maybe_icecream(22), Some(0)); assert_eq!(maybe_icecream(25), None); @@ -29,6 +30,6 @@ mod tests { fn raw_value() { // TODO: Fix this test. How do you get at the value contained in the Option? let icecreams = maybe_icecream(12); - assert_eq!(icecreams, 5); + assert_eq!(icecreams, 0); } } From 4400ce2892188044d510cbabdfead1f0c704bdf8 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 16 Aug 2022 07:32:31 +0000 Subject: [PATCH 452/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 9648f33c..0c07a933 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -212,6 +212,7 @@ authors.
Brian Fakhoury

🖋
Markus Boehme

💻 +
Nico Vromans

🖋 From 2f2f141564f3bfc34c9a0a0d5449ea376f7835f8 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 16 Aug 2022 07:32:32 +0000 Subject: [PATCH 453/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0df89f7e..be5dc21a 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1488,6 +1488,15 @@ "contributions": [ "code" ] + }, + { + "login": "nico-vromans", + "name": "Nico Vromans", + "avatar_url": "https://avatars.githubusercontent.com/u/48183857?v=4", + "profile": "https://github.com/nico-vromans", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From bb6b9e1704a5bbe16a57adc95616409c8c3ea0e2 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 16 Aug 2022 09:41:41 +0200 Subject: [PATCH 454/476] doc: add zulip link --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index afa55c86..b2ac6b92 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,10 @@ Now you should be done! See [CONTRIBUTING.md](./CONTRIBUTING.md). +Development-focused discussion about Rustlings happens in the [**rustlings** stream](https://rust-lang.zulipchat.com/#narrow/stream/334454-rustlings) +on the [Rust Project Zulip](https://rust-lang.zulipchat.com). Feel free to start a new thread there +if you have ideas or suggestions! + ## Contributors ✨ Thanks goes to the wonderful people listed in [AUTHORS.md](./AUTHORS.md) 🎉 From 0a9d34a25a6a262b3f947625a3fa87e8fa10ed7e Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 16 Aug 2022 09:53:40 +0200 Subject: [PATCH 455/476] doc: update changelog --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aae3138..8c782c86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,38 @@ + +## 5.1.0 (2022-08-16) + +#### Features + +- Added a new `rc1` exercise. +- Added a new `cow1` exercise. + +#### Bug Fixes + +- **variables5**: Corrected reference to previous exercise +- **functions4**: Fixed line number reference +- **strings3**: Clarified comment wording +- **traits4, traits5**: Fixed line number reference +- **traits5**: + - Fixed typo in "parameter" + - Made exercise prefer a traits-based solution +- **lifetimes2**: Improved hint +- **threads3**: Fixed typo in hint +- **box1**: Replaced `unimplemented!` with `todo!` +- **errors5**: Provided an explanation for usage of `Box` +- **quiz2**: Fixed a typo +- **macros**: Updated the macros book link +- **options1**: + - Removed unused code + - Added more granular tests +- Fixed some comment syntax shenanigans in info.toml + +#### Housekeeping + +- Fixed a typo in .editorconfig +- Fixed a typo in integration_tests.rs +- Clarified manual installation instructions using `cargo install --path .` +- Added a link to our Zulip in the readme file + ## 5.0.0 (2022-07-16) From 714a8075cc34e3823513cd3ea26bd4a92c1c1129 Mon Sep 17 00:00:00 2001 From: mokou Date: Tue, 16 Aug 2022 09:54:25 +0200 Subject: [PATCH 456/476] chore: bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 ++-- src/main.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 862a8a2e..d28d2c82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "5.0.0" +version = "5.1.0" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 910b5389..ae01278b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "5.0.0" +version = "5.1.0" authors = ["Liv ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/README.md b/README.md index b2ac6b92..f7ed07ca 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ If you get a permission denied message, you might have to exclude the directory Basically: Clone the repository at the latest tag, run `cargo install --path .`. ```bash -# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.0.0) -git clone -b 5.0.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 5.1.0) +git clone -b 5.1.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 0ddb7331..3719f66a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "5.0.0"; +const VERSION: &str = "5.1.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From 4455c22b9aa5e4a6735e3ae67a4c9e75af24128a Mon Sep 17 00:00:00 2001 From: vostok92 Date: Wed, 17 Aug 2022 13:51:17 +0900 Subject: [PATCH 457/476] Update options1.rs Fix assertions --- exercises/options/options1.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index 022d3d66..d1735c2f 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -20,7 +20,7 @@ mod tests { #[test] fn check_icecream() { assert_eq!(maybe_icecream(9), Some(5)); - assert_eq!(maybe_icecream(10), Some(0)); + assert_eq!(maybe_icecream(10), Some(5)); assert_eq!(maybe_icecream(23), Some(0)); assert_eq!(maybe_icecream(22), Some(0)); assert_eq!(maybe_icecream(25), None); @@ -30,6 +30,6 @@ mod tests { fn raw_value() { // TODO: Fix this test. How do you get at the value contained in the Option? let icecreams = maybe_icecream(12); - assert_eq!(icecreams, 0); + assert_eq!(icecreams, 5); } } From 3c1fe226f0a4e651bdb498330ca3ded6ffb477c4 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 17 Aug 2022 08:41:49 +0000 Subject: [PATCH 458/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 0c07a933..b7bf94b0 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -213,6 +213,7 @@ authors.
Brian Fakhoury

🖋
Markus Boehme

💻
Nico Vromans

🖋 +
vostok92

🖋 From 34392662a635f56fc59901f51f92b906f44e822d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 17 Aug 2022 08:41:50 +0000 Subject: [PATCH 459/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index be5dc21a..c5d783f1 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1497,6 +1497,15 @@ "contributions": [ "content" ] + }, + { + "login": "vostok92", + "name": "vostok92", + "avatar_url": "https://avatars.githubusercontent.com/u/540339?v=4", + "profile": "https://github.com/vostok92", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d0c7b06eff3e8959b261145e10f1aaa57ba1e4c3 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 17 Aug 2022 10:43:50 +0200 Subject: [PATCH 460/476] chore: release 5.1.1 --- CHANGELOG.md | 7 +++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 ++-- src/main.rs | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c782c86..cec41c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +## 5.1.1 (2022-08-17) + +#### Bug Fixes + +- Fixed an incorrect assertion in options1 + ## 5.1.0 (2022-08-16) diff --git a/Cargo.lock b/Cargo.lock index d28d2c82..2370e8dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "5.1.0" +version = "5.1.1" dependencies = [ "argh", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index ae01278b..d5fd93c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "5.1.0" +version = "5.1.1" authors = ["Liv ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/README.md b/README.md index f7ed07ca..2392ba9d 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ If you get a permission denied message, you might have to exclude the directory Basically: Clone the repository at the latest tag, run `cargo install --path .`. ```bash -# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.1.0) -git clone -b 5.1.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 5.1.1) +git clone -b 5.1.1 --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 3719f66a..531533ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "5.1.0"; +const VERSION: &str = "5.1.1"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code From 52a29aa84be2a89894f2ad1f5ebdcf153c49f399 Mon Sep 17 00:00:00 2001 From: magnusrodseth <59113973+magnusrodseth@users.noreply.github.com> Date: Wed, 17 Aug 2022 12:50:34 +0200 Subject: [PATCH 461/476] test: Convert main function to working tests --- exercises/options/options2.rs | 41 ++++++++++++++++++++++------------- info.toml | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/exercises/options/options2.rs b/exercises/options/options2.rs index 75b66a37..eca03f0d 100644 --- a/exercises/options/options2.rs +++ b/exercises/options/options2.rs @@ -3,23 +3,34 @@ // I AM NOT DONE -fn main() { - let optional_word = Some(String::from("rustlings")); - // TODO: Make this an if let statement whose value is "Some" type - word = optional_word { - println!("The word is: {}", word); - } else { - println!("The optional word doesn't contain anything"); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn simple_option() { + let target = "rustlings"; + let optional_target = Some(target); + + // TODO: Make this an if let statement whose value is "Some" type + if let Some(word) = optional_target { + assert_eq!(word, target); + } } - let mut optional_integers_vec: Vec> = Vec::new(); - for x in 1..10 { - optional_integers_vec.push(Some(x)); - } + #[test] + fn layered_option() { + let mut range = 10; + let mut optional_integers: Vec> = Vec::new(); + for i in 0..(range + 1) { + optional_integers.push(Some(i)); + } - // TODO: make this a while let statement - remember that vector.pop also adds another layer of Option - // You can stack `Option`'s into while let and if let - integer = optional_integers_vec.pop() { - println!("current value: {}", integer); + // TODO: make this a while let statement - remember that vector.pop also adds another layer of Option + // You can stack `Option`'s into while let and if let + while let Some(Some(integer)) = optional_integers.pop() { + assert_eq!(integer, range); + range -= 1; + } } } diff --git a/info.toml b/info.toml index 9aa11e8a..8bce7216 100644 --- a/info.toml +++ b/info.toml @@ -545,7 +545,7 @@ is the easiest, but how do you do it safely so that it doesn't panic in your fac [[exercises]] name = "options2" path = "exercises/options/options2.rs" -mode = "compile" +mode = "test" hint = """ check out: https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html From 6f44cb1dd237f4d53aa3ecd4676e50cf850c99fe Mon Sep 17 00:00:00 2001 From: magnusrodseth <59113973+magnusrodseth@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:31:53 +0200 Subject: [PATCH 462/476] feat: Add reset command, given a filename --- src/main.rs | 78 ++++++++++++++++++++++++++++++++++++++++------------- src/run.rs | 15 +++++++++++ 2 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 531533ea..3610f827 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ -use crate::exercise::{Exercise, ExerciseList}; use crate::project::RustAnalyzerProject; use crate::run::run; use crate::verify::verify; +use crate::{ + exercise::{Exercise, ExerciseList}, + run::reset, +}; use argh::FromArgs; use console::Emoji; use notify::DebouncedEvent; @@ -47,6 +50,7 @@ enum Subcommands { Verify(VerifyArgs), Watch(WatchArgs), Run(RunArgs), + Reset(ResetArgs), Hint(HintArgs), List(ListArgs), Lsp(LspArgs), @@ -71,6 +75,15 @@ struct RunArgs { name: String, } +#[derive(FromArgs, PartialEq, Debug)] +#[argh(subcommand, name = "reset")] +/// Resets a single exercise +struct ResetArgs { + #[argh(positional)] + /// the name of the exercise + name: String, +} + #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "hint")] /// Returns a hint for the given exercise @@ -85,7 +98,6 @@ struct HintArgs { /// Enable rust-analyzer for exercises struct LspArgs {} - #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "list")] /// Lists the exercises available in Rustlings @@ -164,7 +176,9 @@ fn main() { "Pending" }; let solve_cond = { - (e.looks_done() && subargs.solved) || (!e.looks_done() && subargs.unsolved) || (!subargs.solved && !subargs.unsolved) + (e.looks_done() && subargs.solved) + || (!e.looks_done() && subargs.unsolved) + || (!subargs.solved && !subargs.unsolved) }; if solve_cond && (filter_cond || subargs.filter.is_none()) { let line = if subargs.paths { @@ -205,6 +219,12 @@ fn main() { run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); } + Subcommands::Reset(subargs) => { + let exercise = find_exercise(&subargs.name, &exercises); + + reset(exercise).unwrap_or_else(|_| std::process::exit(1)); + } + Subcommands::Hint(subargs) => { let exercise = find_exercise(&subargs.name, &exercises); @@ -212,7 +232,8 @@ fn main() { } Subcommands::Verify(_subargs) => { - verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1)); + verify(&exercises, (0, exercises.len()), verbose) + .unwrap_or_else(|_| std::process::exit(1)); } Subcommands::Lsp(_subargs) => { @@ -236,12 +257,18 @@ fn main() { Subcommands::Watch(_subargs) => match watch(&exercises, verbose) { Err(e) => { - println!("Error: Could not watch your progress. Error message was {:?}.", e); + println!( + "Error: Could not watch your progress. Error message was {:?}.", + e + ); println!("Most likely you've run out of disk space or your 'inotify limit' has been reached."); std::process::exit(1); } Ok(WatchStatus::Finished) => { - println!("{emoji} All exercises completed! {emoji}", emoji = Emoji("🎉", "★")); + println!( + "{emoji} All exercises completed! {emoji}", + emoji = Emoji("🎉", "★") + ); println!("\n{}\n", FENISH_LINE); } Ok(WatchStatus::Unfinished) => { @@ -252,8 +279,10 @@ fn main() { } } - -fn spawn_watch_shell(failed_exercise_hint: &Arc>>, should_quit: Arc) { +fn spawn_watch_shell( + failed_exercise_hint: &Arc>>, + should_quit: Arc, +) { let failed_exercise_hint = Arc::clone(failed_exercise_hint); println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here."); thread::spawn(move || loop { @@ -290,16 +319,22 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>, should_q fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise { 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) - }) + 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) - }) + exercises + .iter() + .find(|e| e.name == name) + .unwrap_or_else(|| { + println!("No exercise found for '{}'!", name); + std::process::exit(1) + }) } } @@ -337,8 +372,13 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result { let filepath = b.as_path().canonicalize().unwrap(); let pending_exercises = exercises .iter() - .find(|e| filepath.ends_with(&e.path)).into_iter() - .chain(exercises.iter().filter(|e| !e.looks_done() && !filepath.ends_with(&e.path))); + .find(|e| filepath.ends_with(&e.path)) + .into_iter() + .chain( + exercises + .iter() + .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)), + ); let num_done = exercises.iter().filter(|e| e.looks_done()).count(); clear_screen(); match verify(pending_exercises, (num_done, exercises.len()), verbose) { diff --git a/src/run.rs b/src/run.rs index eb558850..826f00a6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,3 +1,5 @@ +use std::process::Command; + use crate::exercise::{Exercise, Mode}; use crate::verify::test; use indicatif::ProgressBar; @@ -15,6 +17,19 @@ pub fn run(exercise: &Exercise, verbose: bool) -> Result<(), ()> { Ok(()) } +// Resets the exercise by stashing the changes. +pub fn reset(exercise: &Exercise) -> Result<(), ()> { + let command = Command::new("git") + .args(["stash", "--"]) + .arg(&exercise.path) + .spawn(); + + match command { + Ok(_) => Ok(()), + Err(_) => Err(()), + } +} + // Invoke the rust compiler on the path of the given exercise // and run the ensuing binary. // This is strictly for non-test binaries, so output is displayed From 0aff5340b5e225b394ac0fdf496824eaa201e19c Mon Sep 17 00:00:00 2001 From: magnusrodseth <59113973+magnusrodseth@users.noreply.github.com> Date: Wed, 17 Aug 2022 16:43:48 +0200 Subject: [PATCH 463/476] test: Add integration tests --- tests/integration_tests.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 0be191f0..1a729232 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -110,6 +110,27 @@ fn run_single_test_no_exercise() { .code(1); } +#[test] +fn reset_single_exercise() { + Command::cargo_bin("rustlings") + .unwrap() + .args(&["reset", "intro1"]) + .assert() + .code(0); +} + +#[test] +fn reset_no_exercise() { + Command::cargo_bin("rustlings") + .unwrap() + .arg("reset") + .assert() + .code(1) + .stderr(predicates::str::contains( + "positional arguments not provided", + )); +} + #[test] fn get_hint_for_single_test() { Command::cargo_bin("rustlings") @@ -126,7 +147,7 @@ fn all_exercises_require_confirmation() { for exercise in glob("exercises/**/*.rs").unwrap() { let path = exercise.unwrap(); if path.file_name().unwrap() == "mod.rs" { - continue + continue; } let source = { let mut file = File::open(&path).unwrap(); From 99ea2cbba7dabb011fc76e4480e27f0bbc6149ad Mon Sep 17 00:00:00 2001 From: magnusrodseth <59113973+magnusrodseth@users.noreply.github.com> Date: Wed, 17 Aug 2022 12:54:23 +0200 Subject: [PATCH 464/476] chore: make options2 not compile deliberately --- exercises/options/options2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/options/options2.rs b/exercises/options/options2.rs index eca03f0d..b1120471 100644 --- a/exercises/options/options2.rs +++ b/exercises/options/options2.rs @@ -13,7 +13,7 @@ mod tests { let optional_target = Some(target); // TODO: Make this an if let statement whose value is "Some" type - if let Some(word) = optional_target { + word = optional_target { assert_eq!(word, target); } } @@ -28,7 +28,7 @@ mod tests { // TODO: make this a while let statement - remember that vector.pop also adds another layer of Option // You can stack `Option`'s into while let and if let - while let Some(Some(integer)) = optional_integers.pop() { + integer = optional_integers.pop() { assert_eq!(integer, range); range -= 1; } From e889c5bb60a123c62b9cb4acbab84c817a2fecfa Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:53:54 +0000 Subject: [PATCH 465/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index b7bf94b0..09a77046 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -214,6 +214,7 @@ authors.
Markus Boehme

💻
Nico Vromans

🖋
vostok92

🖋 +
Magnus Rødseth

🖋 From 2088dfbaf6944b637c436a92a5f2a1e290390aec Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:53:55 +0000 Subject: [PATCH 466/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index c5d783f1..0792bd27 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1506,6 +1506,15 @@ "contributions": [ "content" ] + }, + { + "login": "magnusrodseth", + "name": "Magnus Rødseth", + "avatar_url": "https://avatars.githubusercontent.com/u/59113973?v=4", + "profile": "http://magnusrodseth.vercel.app", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 93f60d3f8d31c209a1e49d1dd149dbe964b1d2a2 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:54:29 +0000 Subject: [PATCH 467/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 09a77046..868f0c8e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -215,6 +215,7 @@ authors.
Nico Vromans

🖋
vostok92

🖋
Magnus Rødseth

🖋 +
rubiesonthesky

🖋 From 50272a58e2a86537a558c0e93d02e6c9ef44a3f2 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 18 Aug 2022 09:54:30 +0000 Subject: [PATCH 468/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0792bd27..6b811617 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1515,6 +1515,15 @@ "contributions": [ "content" ] + }, + { + "login": "rubiesonthesky", + "name": "rubiesonthesky", + "avatar_url": "https://avatars.githubusercontent.com/u/2591240?v=4", + "profile": "https://github.com/rubiesonthesky", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d59dde320b90ac5f5679a8f044746e37faa7289f Mon Sep 17 00:00:00 2001 From: magnusrodseth <59113973+magnusrodseth@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:47:26 +0200 Subject: [PATCH 469/476] chore: Add suggested changes --- src/main.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3610f827..9bf75e38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,7 @@ +use crate::exercise::{Exercise, ExerciseList}; use crate::project::RustAnalyzerProject; -use crate::run::run; +use crate::run::{reset, run}; use crate::verify::verify; -use crate::{ - exercise::{Exercise, ExerciseList}, - run::reset, -}; use argh::FromArgs; use console::Emoji; use notify::DebouncedEvent; @@ -77,7 +74,7 @@ struct RunArgs { #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "reset")] -/// Resets a single exercise +/// Resets a single exercise using "git stash -- " struct ResetArgs { #[argh(positional)] /// the name of the exercise From 86506fa5fd5441c98e4ac74169d10578b77cd770 Mon Sep 17 00:00:00 2001 From: Gabriel Bianconi <1275491+GabrielBianconi@users.noreply.github.com> Date: Mon, 22 Aug 2022 23:47:23 -0400 Subject: [PATCH 470/476] Fix typo in `threads3` hint --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index 8bce7216..060643d7 100644 --- a/info.toml +++ b/info.toml @@ -1012,7 +1012,7 @@ hint = """ An alternate way to handle concurrency between threads is to use a mpsc (multiple producer, single consumer) channel to communicate. With both a sending end and a receiving end, it's possible to -send values in one thread and receieve them in another. +send values in one thread and receive them in another. Multiple producers are possible by using clone() to create a duplicate of the original sending end. See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info. From 6c2630afcff34b634cdf0843d6b01cade2efc622 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 24 Aug 2022 09:15:51 +0000 Subject: [PATCH 471/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 868f0c8e..02cbf0ed 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -216,6 +216,7 @@ authors.
vostok92

🖋
Magnus Rødseth

🖋
rubiesonthesky

🖋 +
Gabriel Bianconi

🖋 From b92e7b968ffb1343f6ee11c392c29099afbdae66 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 24 Aug 2022 09:15:52 +0000 Subject: [PATCH 472/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6b811617..e061d153 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1524,6 +1524,15 @@ "contributions": [ "content" ] + }, + { + "login": "GabrielBianconi", + "name": "Gabriel Bianconi", + "avatar_url": "https://avatars.githubusercontent.com/u/1275491?v=4", + "profile": "http://www.gabrielbianconi.com/", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From d6e26bb350e423a8f2a90d9405060fdaf9893736 Mon Sep 17 00:00:00 2001 From: Kody Low Date: Wed, 24 Aug 2022 08:33:17 -0700 Subject: [PATCH 473/476] 2nd assert is for greater than or equal to, not "more than" like it says in the instructions --- exercises/quiz1.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 8d05b110..d1e76e59 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -5,7 +5,7 @@ // - If // 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 33e501981aa71a986db5db72fea5e6635e6c58b4 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 10:12:14 +0000 Subject: [PATCH 474/476] docs: update AUTHORS.md [skip ci] --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 02cbf0ed..8edf09bf 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -217,6 +217,7 @@ authors.
Magnus Rødseth

🖋
rubiesonthesky

🖋
Gabriel Bianconi

🖋 +
Kody Low

🖋 From bf95a345533605d8fec4dbd011d4269961ed415d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 10:12:15 +0000 Subject: [PATCH 475/476] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index e061d153..f2033dcd 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1533,6 +1533,15 @@ "contributions": [ "content" ] + }, + { + "login": "Kodylow", + "name": "Kody Low", + "avatar_url": "https://avatars.githubusercontent.com/u/74332828?v=4", + "profile": "https://github.com/Kodylow", + "contributions": [ + "content" + ] } ], "contributorsPerLine": 8, From 3309a01b5e7f18da6409435151e8ebe0c0a697dc Mon Sep 17 00:00:00 2001 From: mokou Date: Sat, 27 Aug 2022 19:48:15 +0100 Subject: [PATCH 476/476] chore: release 5.2.0 --- CHANGELOG.md | 17 +++++++++++++++++ Cargo.toml | 2 +- src/main.rs | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec41c59..0b15cf99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ + +## 5.2.0 (2022-08-27) + +#### Added + +- Added a `reset` command + +#### Changed + +- **options2**: Convert the exercise to use tests + +#### Fixed + +- **threads3**: Fixed a typo +- **quiz1**: Adjusted the explanations to be consistent with + the tests + ## 5.1.1 (2022-08-17) diff --git a/Cargo.toml b/Cargo.toml index d5fd93c7..25cd7bfe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "5.1.1" +version = "5.2.0" authors = ["Liv ", "Carol (Nichols || Goulding) "] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 9bf75e38..8eebc086 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ mod run; mod verify; // In sync with crate version -const VERSION: &str = "5.1.1"; +const VERSION: &str = "5.2.0"; #[derive(FromArgs, PartialEq, Debug)] /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code