From ddd98ad75d3668fbb10eff74374148aa5ed2344d Mon Sep 17 00:00:00 2001 From: iamcastelli Date: Sat, 27 Jun 2020 15:58:53 +0400 Subject: [PATCH 01/16] fix: Change then to than `than` makes more grammatical sense than `then` in this context. --- info.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.toml b/info.toml index ee4ab2f6..46e353ff 100644 --- a/info.toml +++ b/info.toml @@ -64,7 +64,7 @@ hint = """ We know about variables and mutability, but there is another important type of variable available; constants. Constants are always immutable and they are declared with keyword 'const' rather -then keyword 'let'. +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': From f9ccc6a289ca5fed784fd45878b163e633bfdba1 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 8 Jul 2020 11:35:27 +0200 Subject: [PATCH 02/16] release: 4.0.0 --- CHANGELOG.md | 42 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f72c9607..594987c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,45 @@ + +## 4.0.0 (2020-07-08) + +#### Breaking Changes + +* Add a --nocapture option to display test harnesses' outputs ([8ad5f9bf](https://github.com/rust-lang/rustlings/commit/8ad5f9bf531a4848b1104b7b389a20171624c82f) +* Rename test to quiz, fixes #244 ([010a0456](https://github.com/rust-lang/rustlings/commit/010a04569282149cea7f7a76fc4d7f4c9f0f08dd) + +#### Features + +* Add traits README ([173bb141](https://github.com/rust-lang/rustlings/commit/173bb14140c5530cbdb59e53ace3991a99d804af)) +* Add box1.rs exercise ([7479a473](https://github.com/rust-lang/rustlings/commit/7479a4737bdcac347322ad0883ca528c8675e720)) +* Rewrite try_from_into (#393) ([763aa6e3](https://github.com/rust-lang/rustlings/commit/763aa6e378a586caae2d8d63755a85eeba227933)) +* Add if2 exercise ([1da84b5f](https://github.com/rust-lang/rustlings/commit/1da84b5f7c489f65bd683c244f13c7d1ee812df0)) +* Added exercise structs3.rs ([b66e2e09](https://github.com/rust-lang/rustlings/commit/b66e2e09622243e086a0f1258dd27e1a2d61c891)) +* Add exercise variables6 covering const (#352) ([5999acd2](https://github.com/rust-lang/rustlings/commit/5999acd24a4f203292be36e0fd18d385887ec481)) + +#### Bug Fixes + +* Change then to than ([ddd98ad7](https://github.com/rust-lang/rustlings/commit/ddd98ad75d3668fbb10eff74374148aa5ed2344d)) +* rename quiz1 to tests1 in info (#420) ([0dd1c6ca](https://github.com/rust-lang/rustlings/commit/0dd1c6ca6b389789e0972aa955fe17aa15c95f29)) +* fix quiz naming inconsistency (#421) ([5563adbb](https://github.com/rust-lang/rustlings/commit/5563adbb890587fc48fbbc9c4028642687f1e85b)) +* confine the user further in variable exercises ([06ef4cc6](https://github.com/rust-lang/rustlings/commit/06ef4cc654e75d22a526812919ee49b8956280bf)) +* update iterator and macro text for typos and clarity ([95900828](https://github.com/rust-lang/rustlings/commit/959008284834bece0196a01e17ac69a7e3590116)) +* update generics2 closes #362 ([964c974a](https://github.com/rust-lang/rustlings/commit/964c974a0274199d755073b917c2bc5da0c9b4f1)) +* confusing comment in conversions/try_from_into.rs ([c9e4f2cf](https://github.com/rust-lang/rustlings/commit/c9e4f2cfb4c48d0b7451263cfb43b9426438122d)) +* **arc1:** Passively introduce attributes (#429) ([113cdae2](https://github.com/rust-lang/rustlings/commit/113cdae2d4e4c55905e8056ad326ede7fd7de356)) +* **box1:** fix comment typo (#426) ([bb2ca251](https://github.com/rust-lang/rustlings/commit/bb2ca251106b27a7272d9a30872904dd1376654c)) +* **errorsn:** Try harder to confine the user. (#388) ([2b20c8a0](https://github.com/rust-lang/rustlings/commit/2b20c8a0f5774d07c58d110d75879f33fc6273b5)) +* **from_into.rs:** typo ([a901499e](https://github.com/rust-lang/rustlings/commit/a901499ededd3ce1995164700514fe4e9a0373ea)) +* **generics2:** Guide students to the answer (#430) ([e6bd8021](https://github.com/rust-lang/rustlings/commit/e6bd8021d9a7dd06feebc30c9d5f953901d7b419)) +* **installation:** + * Provide a backup git reference when tag can't be curl ([9e4fb100](https://github.com/rust-lang/rustlings/commit/9e4fb1009f1c9e3433915c03e22c2af422e5c5fe)) + * Check if python is available while checking for git,rustc and cargo ([9cfb617d](https://github.com/rust-lang/rustlings/commit/9cfb617d5b0451b4b51644a1298965390cda9884)) +* **option1:** + * Don't add only zeros to the numbers array ([cce6a442](https://github.com/rust-lang/rustlings/commit/cce6a4427718724a9096800754cd3abeca6a1580)) + * Add cast to usize, as it is confusing in the context of an exercise about Option ([f6cffc7e](https://github.com/rust-lang/rustlings/commit/f6cffc7e487b42f15a6f958e49704c93a8d4465b)) +* **option2:** Add TODO to comments (#400) ([10967bce](https://github.com/rust-lang/rustlings/commit/10967bce57682812dc0891a9f9757da1a9d87404)) +* **options1:** Add hint about Array Initialization (#389) ([9f75554f](https://github.com/rust-lang/rustlings/commit/9f75554f2a30295996f03f0160b98c0458305502)) +* **test2:** name of type String and &str (#394) ([d6c0a688](https://github.com/rust-lang/rustlings/commit/d6c0a688e6a96f93ad60d540d4b326f342fc0d45)) +* **variables6:** minor typo (#419) ([524e17df](https://github.com/rust-lang/rustlings/commit/524e17df10db95f7b90a0f75cc8997182a8a4094)) + ## 3.0.0 (2020-04-11) diff --git a/Cargo.toml b/Cargo.toml index 3481a886..d4180da2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustlings" -version = "3.0.0" +version = "4.0.0" authors = ["Marisa ", "Carol (Nichols || Goulding) "] edition = "2018" diff --git a/README.md b/README.md index 6724f05a..3e260122 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,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/3.0.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) +git checkout tags/4.0.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest) cargo install --force --path . ``` From e823bef97063560170c6c286ae03e40fb50ea5b8 Mon Sep 17 00:00:00 2001 From: mokou Date: Wed, 8 Jul 2020 11:43:08 +0200 Subject: [PATCH 03/16] docs: Add missing closing brackets to changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594987c1..0d984eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ #### Breaking Changes -* Add a --nocapture option to display test harnesses' outputs ([8ad5f9bf](https://github.com/rust-lang/rustlings/commit/8ad5f9bf531a4848b1104b7b389a20171624c82f) -* Rename test to quiz, fixes #244 ([010a0456](https://github.com/rust-lang/rustlings/commit/010a04569282149cea7f7a76fc4d7f4c9f0f08dd) +* Add a --nocapture option to display test harnesses' outputs ([8ad5f9bf](https://github.com/rust-lang/rustlings/commit/8ad5f9bf531a4848b1104b7b389a20171624c82f)) +* Rename test to quiz, fixes #244 ([010a0456](https://github.com/rust-lang/rustlings/commit/010a04569282149cea7f7a76fc4d7f4c9f0f08dd)) #### Features From 816b1f5e85d6cc6e72673813a85d0ada2a8f84af Mon Sep 17 00:00:00 2001 From: Alexx Roche Date: Wed, 8 Jul 2020 11:51:12 +0200 Subject: [PATCH 04/16] feat: Remind the user of the hint option (#425) Suggestion from AbdouSeck https://github.com/rust-lang/rustlings/issues/424#issuecomment-639870331 for when the student's code has errors. --- src/verify.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/verify.rs b/src/verify.rs index fac04919..807bea9e 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -65,6 +65,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { Err(output) => { warn!("Ran {} with errors", exercise); println!("{}", output.stdout); + println!("{}", output.stderr); return Err(()); } }; From 4b6540c71adabad647de8a09e57295e7c7c7d794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DEWA=20Kazuyuki/=E5=87=BA=E7=BE=BD=E5=92=8C=E4=B9=8B?= Date: Wed, 8 Jul 2020 18:56:43 +0900 Subject: [PATCH 05/16] fix(enums3): Update Message::ChangeColor to take a tuple. (#457) --- exercises/enums/enums3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index 4b0be975..e9621b8e 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -51,7 +51,7 @@ mod tests { position: Point{ x: 0, y: 0 }, color: (0, 0, 0) }; - state.process(Message::ChangeColor(255, 0, 255)); + state.process(Message::ChangeColor((255, 0, 255))); state.process(Message::Echo(String::from("hello world"))); state.process(Message::Move(Point{ x: 10, y: 15 })); state.process(Message::Quit); From 106dbbc341bd7846745b37e2203e206abf83ed20 Mon Sep 17 00:00:00 2001 From: Philip Pokarowski <2538022+Nuc1eoN@users.noreply.github.com> Date: Thu, 9 Jul 2020 09:25:50 +0200 Subject: [PATCH 06/16] Update README.md (#464) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e260122..f1fc764c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Then, same as above, run `rustlings` to get started. The exercises are sorted by topic and can be found in the subdirectory `rustlings/exercises/`. For every topic there is an additional README file with some resources to get you started on the topic. We really recommend that you have a look at them before you start. -The task is simple. Most exercises contain an error that keep it from compiling, and it's up to you to fix it! Some exercises are also run as tests, but rustlings handles them all the same. To run the exercises in the recommended order, execute: +The task is simple. Most exercises contain an error that keep them from compiling, and it's up to you to fix it! Some exercises are also run as tests, but rustlings handles them all the same. To run the exercises in the recommended order, execute: ```bash rustlings watch From bb5f404e35f0091b4beb691105e7ed2a94ce4a13 Mon Sep 17 00:00:00 2001 From: Benjamin Jones Date: Fri, 10 Jul 2020 19:01:38 -0700 Subject: [PATCH 07/16] chore: Alter whitespace for consistency * Add newline after "I AM DONE" in exercises for consistency * Remove trailing whitespace from exercises --- exercises/conversions/as_ref_mut.rs | 1 + exercises/conversions/from_into.rs | 4 +++- exercises/conversions/using_as.rs | 6 ++++-- exercises/generics/generics1.rs | 2 +- exercises/generics/generics2.rs | 5 +++-- exercises/generics/generics3.rs | 21 ++++++++++--------- exercises/primitive_types/primitive_types3.rs | 2 +- exercises/structs/structs3.rs | 6 +++--- exercises/traits/traits1.rs | 9 ++++---- exercises/traits/traits2.rs | 7 +++---- 10 files changed, 34 insertions(+), 29 deletions(-) diff --git a/exercises/conversions/as_ref_mut.rs b/exercises/conversions/as_ref_mut.rs index 963c0f2d..84f4a60c 100644 --- a/exercises/conversions/as_ref_mut.rs +++ b/exercises/conversions/as_ref_mut.rs @@ -3,6 +3,7 @@ // and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively. // I AM NOT DONE + // Obtain the number of bytes (not characters) in the given argument // Add the AsRef trait appropriately as a trait bound fn byte_counter(arg: T) -> usize { diff --git a/exercises/conversions/from_into.rs b/exercises/conversions/from_into.rs index 8fb9eb05..4f4da538 100644 --- a/exercises/conversions/from_into.rs +++ b/exercises/conversions/from_into.rs @@ -18,7 +18,6 @@ impl Default for Person { } } -// I AM NOT DONE // Your task is to complete this implementation // in order for the line `let p = Person::from("Mark,20")` to compile // Please note that you'll need to parse the age component into a `usize` @@ -33,6 +32,9 @@ impl Default for Person { // 5. Extract the other element from the split operation and parse it into a `usize` as the age // If while parsing the age, something goes wrong, then return the default of Person // Otherwise, then return an instantiated Person object with the results + +// I AM NOT DONE + impl From<&str> for Person { fn from(s: &str) -> Person { } diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 54f96515..922abae0 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -1,9 +1,11 @@ // Type casting in Rust is done via the usage of the `as` operator. // Please note that the `as` operator is not only used when type casting. // It also helps with renaming imports. +// +// The goal is to make sure that the division does not fail to compile // I AM NOT DONE -// The goal is to make sure that the division does not fail to compile + fn average(values: &[f64]) -> f64 { let total = values .iter() @@ -14,4 +16,4 @@ fn average(values: &[f64]) -> f64 { fn main() { let values = [3.5, 0.3, 13.0, 11.7]; println!("{}", average(&values)); -} \ No newline at end of file +} diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index d075a4d2..1e6ae9d7 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -1,4 +1,4 @@ -// This shopping list program isn't compiling! +// This shopping list program isn't compiling! // Use your knowledge of generics to fix it. // I AM NOT DONE diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 23025aaa..20c21279 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -2,6 +2,7 @@ // Rewrite it using generics so that it supports wrapping ANY type. // I AM NOT DONE + struct Wrapper { value: u32 } @@ -18,11 +19,11 @@ mod tests { #[test] fn store_u32_in_wrapper() { - assert_eq!(Wrapper::new(42).value, 42); + assert_eq!(Wrapper::new(42).value, 42); } #[test] fn store_str_in_wrapper() { assert_eq!(Wrapper::new("Foo").value, "Foo"); } -} \ No newline at end of file +} diff --git a/exercises/generics/generics3.rs b/exercises/generics/generics3.rs index c76425c3..760028ed 100644 --- a/exercises/generics/generics3.rs +++ b/exercises/generics/generics3.rs @@ -1,13 +1,14 @@ // 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 +// 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 to support alphabetical report cards, thereby making +// Make the necessary code changes to support alphabetical report cards, thereby making // the second test pass. // I AM NOT DONE + pub struct ReportCard { pub grade: f32, pub student_name: String, @@ -16,7 +17,7 @@ pub struct ReportCard { impl ReportCard { pub fn print(&self) -> String { - format!("{} ({}) - achieved a grade of {}", + format!("{} ({}) - achieved a grade of {}", &self.student_name, &self.student_age, &self.grade) } } @@ -28,8 +29,8 @@ mod tests { #[test] fn generate_numeric_report_card() { let report_card = ReportCard { - grade: 2.1, - student_name: "Tom Wriggle".to_string(), + 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"); @@ -39,10 +40,10 @@ mod tests { 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(), + 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+"); } -} \ No newline at end of file +} diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index dfd6351c..aaa518be 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -1,5 +1,5 @@ // primitive_types3.rs -// Create an array with at least 100 elements in it where the ??? is. +// Create an array with at least 100 elements in it where the ??? is. // Execute `rustlings hint primitive_types3` for hints! // I AM NOT DONE diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 5503ce15..883c803f 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -47,7 +47,7 @@ mod tests { fn create_international_package() { let sender_country = String::from("Spain"); let recipient_country = String::from("Russia"); - + let package = Package::new(sender_country, recipient_country, 1200); assert!(package.is_international()); @@ -59,9 +59,9 @@ mod tests { let recipient_country = String::from("Spain"); let cents_per_kg = ???; - + let package = Package::new(sender_country, recipient_country, 1500); - + assert_eq!(package.get_fees(cents_per_kg), 4500); } } diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 8253ef80..2ef9e11b 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -1,21 +1,21 @@ // traits1.rs // Time to implement some traits! -// +// // Your task is to implement the trait // `AppendBar' for the type `String'. -// +// // The trait AppendBar has only one function, // which appends "Bar" to any object // implementing this trait. // I AM NOT DONE + trait AppendBar { fn append_bar(self) -> Self; } impl AppendBar for String { //Add your code here - } fn main() { @@ -40,5 +40,4 @@ mod tests { String::from("BarBar") ); } - -} \ No newline at end of file +} diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 7f5014d0..b9a13a45 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -1,12 +1,12 @@ // traits2.rs -// +// // Your task is to implement the trait // `AppendBar' for a vector of strings. -// +// // To implement this trait, consider for // a moment what it means to 'append "Bar"' // to a vector of strings. -// +// // No boiler plate code this time, // you can do this! @@ -31,5 +31,4 @@ mod tests { assert_eq!(foo.pop().unwrap(), String::from("Bar")); assert_eq!(foo.pop().unwrap(), String::from("Foo")); } - } From c52be7dfcbfb99c40002f22efd32972915efebe1 Mon Sep 17 00:00:00 2001 From: Eli Blaney <5651165+eliblaney@users.noreply.github.com> Date: Sun, 12 Jul 2020 02:44:11 -0500 Subject: [PATCH 08/16] docs: Add uninstall info to README.md * docs: Add uninstall info to README.md * docs: Format commands as bash block --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f1fc764c..47ac4b0e 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,17 @@ rustlings hint myExercise1 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`. +## 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. + +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 +``` + ## Completion Rustlings isn't done; there are a couple of sections that are very experimental and don't have proper documentation. These include: From 523d18b873a319f7c09262f44bd40e2fab1830e5 Mon Sep 17 00:00:00 2001 From: Chad Dougherty Date: Mon, 13 Jul 2020 05:39:05 -0400 Subject: [PATCH 09/16] feat(try_from_into): Add insufficient length test (#469) --- exercises/conversions/try_from_into.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index dbdbe00e..9e452f28 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -127,4 +127,10 @@ mod tests { let v = vec![0, 0, 0, 0]; let _ = Color::try_from(&v[..]).unwrap(); } + #[test] + #[should_panic] + fn test_slice_insufficient_length() { + let v = vec![0, 0]; + let _ = Color::try_from(&v[..]).unwrap(); + } } From 4821a8be94af4f669042a06ab917934cfacd032f Mon Sep 17 00:00:00 2001 From: Ryan McQuen Date: Thu, 23 Jul 2020 10:20:21 -0700 Subject: [PATCH 10/16] feat: Add gitpod support (#473) --- .gitpod.yml | 7 +++++++ README.md | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..46b1a6a8 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,7 @@ +tasks: + - init: /workspace/rustlings/install.sh + command: /workspace/.cargo/bin/rustlings watch + +vscode: + extensions: + - rust-lang.rust@0.7.8:CvNqMTgDdt3UXt+6BCDTVg== diff --git a/README.md b/README.md index 47ac4b0e..7fba9d8c 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,12 @@ 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. +## Browser: + +[Run on Repl.it](https://repl.it/github/rust-lang/rustlings) + +[Open in Gitpod](https://gitpod.io/#https://github.com/rust-lang/rustlings) + ## Manually Basically: Clone the repository, checkout to the latest tag, run `cargo install`. From 8f7b5bd00eb83542b959830ef55192d2d76db90a Mon Sep 17 00:00:00 2001 From: Ryan McQuen Date: Thu, 23 Jul 2020 10:21:15 -0700 Subject: [PATCH 11/16] feat: Add ability to run rustlings on repl.it (#471) Co-authored-by: fmoko --- .replit | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .replit diff --git a/.replit b/.replit new file mode 100644 index 00000000..8462a6fc --- /dev/null +++ b/.replit @@ -0,0 +1,2 @@ +language = "rust" +run = "[ -x ~/.cargo/bin/rustlings ] && ~/.cargo/bin/rustlings watch || ./install.sh" From 4f2468e14f574a93a2e9b688367b5752ed96ae7b Mon Sep 17 00:00:00 2001 From: Adi Vaknin Date: Thu, 23 Jul 2020 21:23:27 +0300 Subject: [PATCH 12/16] feat(cli): Added 'cls' command to 'watch' mode (#474) --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index aa67aca6..0e1291c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,15 +143,18 @@ 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"); + println!("Type 'hint' to get help or 'clear' to clear the screen"); thread::spawn(move || loop { let mut input = String::new(); match io::stdin().read_line(&mut input) { Ok(_) => { - if input.trim().eq("hint") { + let input = input.trim(); + if input.eq("hint") { if let Some(hint) = &*failed_exercise_hint.lock().unwrap() { println!("{}", hint); } + } else if input.eq("clear") { + println!("\x1B[2J\x1B[1;1H"); } else { println!("unknown command: {}", input); } From 38a615f407f439158dccc0cb20d36ee70fe33c27 Mon Sep 17 00:00:00 2001 From: Robby Date: Fri, 24 Jul 2020 19:23:01 +0800 Subject: [PATCH 13/16] chore: add .vscode to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6094e5c1..06de8710 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target/ exercises/clippy/Cargo.toml exercises/clippy/Cargo.lock .idea +.vscode From 1cc40bc9ce95c23d56f6d91fa1c4deb646231fef Mon Sep 17 00:00:00 2001 From: Dany Marcoux Date: Mon, 3 Aug 2020 22:16:14 +0200 Subject: [PATCH 14/16] fix: Update rustlings version in Cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 52c8ed45..732a4b59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "rustlings" -version = "3.0.0" +version = "4.0.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)", From 3144d3ae63963eae6bc8469a48dc0e586d77596d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 10 Aug 2020 10:24:21 -0400 Subject: [PATCH 15/16] chore: Run rustfmt on exercises --- exercises/conversions/from_str.rs | 1 - exercises/conversions/try_from_into.rs | 2 +- exercises/conversions/using_as.rs | 4 +--- exercises/enums/enums2.rs | 4 ++-- exercises/enums/enums3.rs | 13 ++++++------- exercises/generics/generics1.rs | 1 - exercises/generics/generics2.rs | 2 +- exercises/generics/generics3.rs | 10 ++++++++-- exercises/macros/macros4.rs | 4 ++-- exercises/standard_library_types/box1.rs | 5 ++++- exercises/structs/structs3.rs | 6 +++++- exercises/traits/traits2.rs | 3 --- 12 files changed, 30 insertions(+), 25 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 014d0549..af9eee6d 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -82,5 +82,4 @@ mod tests { fn missing_name_and_invalid_age() { ",one".parse::().unwrap(); } - } diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 9e452f28..b830c166 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -2,7 +2,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 -use std::convert::{TryInto, TryFrom}; +use std::convert::{TryFrom, TryInto}; #[derive(Debug)] struct Color { diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 922abae0..b3c197f8 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -7,9 +7,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().fold(0.0, |a, b| a + b); total / values.len() } diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index 52ccb221..ec32d952 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -16,10 +16,10 @@ impl Message { fn main() { let messages = [ - Message::Move{ x: 10, y: 30 }, + Message::Move { x: 10, y: 30 }, Message::Echo(String::from("hello world")), Message::ChangeColor(200, 255, 255), - Message::Quit + Message::Quit, ]; for message in &messages { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index e9621b8e..178b40c4 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -9,13 +9,13 @@ enum Message { struct Point { x: u8, - y: u8 + y: u8, } struct State { color: (u8, u8, u8), position: Point, - quit: bool + quit: bool, } impl State { @@ -46,14 +46,14 @@ mod tests { #[test] fn test_match_message_call() { - let mut state = State{ + let mut state = State { quit: false, - position: Point{ x: 0, y: 0 }, - color: (0, 0, 0) + position: Point { x: 0, y: 0 }, + color: (0, 0, 0), }; state.process(Message::ChangeColor((255, 0, 255))); state.process(Message::Echo(String::from("hello world"))); - state.process(Message::Move(Point{ x: 10, y: 15 })); + state.process(Message::Move(Point { x: 10, y: 15 })); state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255)); @@ -61,5 +61,4 @@ mod tests { assert_eq!(state.position.y, 15); assert_eq!(state.quit, true); } - } diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index 1e6ae9d7..967287ef 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -7,4 +7,3 @@ fn main() { let mut shopping_list: Vec = Vec::new(); shopping_list.push("milk"); } - diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 20c21279..0cb59adc 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -4,7 +4,7 @@ // I AM NOT DONE struct Wrapper { - value: u32 + value: u32, } impl Wrapper { diff --git a/exercises/generics/generics3.rs b/exercises/generics/generics3.rs index 760028ed..5c745e25 100644 --- a/exercises/generics/generics3.rs +++ b/exercises/generics/generics3.rs @@ -33,7 +33,10 @@ mod tests { student_name: "Tom Wriggle".to_string(), student_age: 12, }; - assert_eq!(report_card.print(), "Tom Wriggle (12) - achieved a grade of 2.1"); + assert_eq!( + report_card.print(), + "Tom Wriggle (12) - achieved a grade of 2.1" + ); } #[test] @@ -44,6 +47,9 @@ mod tests { student_name: "Gary Plotter".to_string(), student_age: 11, }; - assert_eq!(report_card.print(), "Gary Plotter (11) - achieved a grade of A+"); + assert_eq!( + report_card.print(), + "Gary Plotter (11) - achieved a grade of A+" + ); } } diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index 3a748078..1b550f43 100644 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -6,10 +6,10 @@ macro_rules! my_macro { () => { println!("Check out my macro!"); - } + }; ($val:expr) => { println!("Look at this other macro: {}", $val); - } + }; } fn main() { diff --git a/exercises/standard_library_types/box1.rs b/exercises/standard_library_types/box1.rs index f2654ce2..f312f3d6 100644 --- a/exercises/standard_library_types/box1.rs +++ b/exercises/standard_library_types/box1.rs @@ -26,7 +26,10 @@ pub enum List { fn main() { println!("This is an empty cons list: {:?}", create_empty_list()); - println!("This is a non-empty cons list: {:?}", create_non_empty_list()); + println!( + "This is a non-empty cons list: {:?}", + create_non_empty_list() + ); } pub fn create_empty_list() -> List { diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 883c803f..36d46e90 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -17,7 +17,11 @@ impl Package { if weight_in_grams <= 0 { // Something goes here... } else { - return Package {sender_country, recipient_country, weight_in_grams}; + return Package { + sender_country, + recipient_country, + weight_in_grams, + }; } } diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index b9a13a45..916c3c4b 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -18,9 +18,6 @@ trait AppendBar { //TODO: Add your code here - - - #[cfg(test)] mod tests { use super::*; From 81f8c2f83c6bb5c239fd2e0cf856d1535692af3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 10 Aug 2020 10:42:54 -0400 Subject: [PATCH 16/16] chore: Run cargo fmt --- src/exercise.rs | 5 +++-- src/main.rs | 4 +--- src/verify.rs | 6 ++---- tests/integration_tests.rs | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index 2108d81e..e70538bb 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -167,9 +167,10 @@ path = "{}.rs""#, fn run(&self) -> Result { let arg = match self.mode { Mode::Test => "--show-output", - _ => "" + _ => "", }; - let cmd = Command::new(&temp_file()).arg(arg) + let cmd = Command::new(&temp_file()) + .arg(arg) .output() .expect("Failed to run 'run' command"); diff --git a/src/main.rs b/src/main.rs index 0e1291c3..b5814bfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,9 +126,7 @@ fn main() { ); 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!("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:"); diff --git a/src/verify.rs b/src/verify.rs index 807bea9e..00e45c8c 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -9,7 +9,7 @@ use indicatif::ProgressBar; // determines whether or not the test harness outputs are displayed. pub fn verify<'a>( start_at: impl IntoIterator, - verbose: bool + verbose: bool, ) -> Result<(), &'a Exercise> { for exercise in start_at { let compile_result = match exercise.mode { @@ -77,9 +77,7 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { // Compile the given Exercise as a test harness and display // the output if verbose is set to true -fn compile_and_test( - exercise: &Exercise, run_mode: RunMode, verbose: bool -) -> Result { +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.enable_steady_tick(100); diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 0f49b5a8..2baf9b86 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -180,4 +180,4 @@ fn run_single_test_success_without_output() { .assert() .code(0) .stdout(predicates::str::contains("THIS TEST TOO SHALL PAS").not()); -} \ No newline at end of file +}