From 2a5542f2a22998cb91bc5a46451fd608f4c8362e Mon Sep 17 00:00:00 2001 From: Benni-Math Date: Sun, 15 May 2022 16:36:26 -0400 Subject: [PATCH] My work so far --- .all-contributorsrc | 81 ------- .clog.toml | 4 + .gitpod.yml | 2 +- AUTHORS.md | 11 - CHANGELOG.md | 66 +----- Cargo.lock | 148 +++++++++++-- Cargo.toml | 18 +- README.md | 197 +----------------- default_out.txt | 25 +++ exercises/collections/hashmap1.rs | 6 +- exercises/collections/hashmap2.rs | 7 +- exercises/collections/vec1.rs | 7 +- exercises/collections/vec2.rs | 4 +- exercises/conversions/using_as.rs | 2 +- exercises/enums/enums1.rs | 6 +- exercises/enums/enums2.rs | 6 +- exercises/enums/enums3.rs | 13 +- exercises/error_handling/errors1.rs | 16 +- exercises/error_handling/errors2.rs | 4 +- exercises/error_handling/errors3.rs | 7 +- exercises/error_handling/errors4.rs | 9 +- exercises/error_handling/errors5.rs | 7 +- exercises/error_handling/errors6.rs | 13 +- exercises/functions/functions1.rs | 6 +- exercises/functions/functions2.rs | 4 +- exercises/functions/functions3.rs | 4 +- exercises/functions/functions4.rs | 4 +- exercises/functions/functions5.rs | 4 +- exercises/generics/generics1.rs | 4 +- exercises/generics/generics2.rs | 10 +- exercises/generics/generics3.rs | 11 +- exercises/if/if1.rs | 3 +- exercises/if/if2.rs | 5 +- exercises/intro/intro1.rs | 2 - exercises/intro/intro2.rs | 5 +- exercises/modules/modules1.rs | 4 +- exercises/modules/modules2.rs | 6 +- exercises/modules/modules3.rs | 4 +- exercises/move_semantics/mod.rs | 1 - exercises/move_semantics/move_semantics1.rs | 4 +- exercises/move_semantics/move_semantics2.rs | 15 +- exercises/move_semantics/move_semantics3.rs | 10 +- exercises/move_semantics/move_semantics4.rs | 8 +- exercises/move_semantics/move_semantics5.rs | 4 +- exercises/move_semantics/move_semantics6.rs | 12 +- exercises/option/option1.rs | 10 +- exercises/option/option2.rs | 8 +- exercises/option/option3.rs | 4 +- exercises/primitive_types/primitive_types1.rs | 4 +- exercises/primitive_types/primitive_types2.rs | 4 +- exercises/primitive_types/primitive_types3.rs | 4 +- exercises/primitive_types/primitive_types4.rs | 4 +- exercises/primitive_types/primitive_types5.rs | 4 +- exercises/primitive_types/primitive_types6.rs | 4 +- exercises/quiz1.rs | 9 +- exercises/quiz2.rs | 22 +- exercises/quiz3.rs | 6 +- exercises/standard_library_types/arc1.rs | 7 +- exercises/standard_library_types/box1.rs | 8 +- exercises/strings/strings1.rs | 4 +- exercises/strings/strings2.rs | 4 +- exercises/structs/structs1.rs | 22 +- exercises/structs/structs2.rs | 5 +- exercises/structs/structs3.rs | 12 +- exercises/tests/tests1.rs | 4 +- exercises/tests/tests2.rs | 4 +- exercises/tests/tests3.rs | 6 +- exercises/traits/traits1.rs | 6 +- exercises/traits/traits2.rs | 8 +- exercises/variables/variables1.rs | 4 +- exercises/variables/variables2.rs | 4 +- exercises/variables/variables3.rs | 4 +- exercises/variables/variables4.rs | 4 +- exercises/variables/variables5.rs | 4 +- exercises/variables/variables6.rs | 4 +- info.toml | 8 +- install.ps1 | 2 +- install.sh | 26 +-- src/main.rs | 167 ++++++++------- src/run.rs | 4 +- src/verify.rs | 33 +-- tests/integration_tests.rs | 3 - 82 files changed, 478 insertions(+), 751 deletions(-) create mode 100644 .clog.toml create mode 100644 default_out.txt diff --git a/.all-contributorsrc b/.all-contributorsrc index 03c84b70..24832b42 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1119,87 +1119,6 @@ "contributions": [ "content" ] - }, - { - "login": "ragreenburg", - "name": "ragreenburg", - "avatar_url": "https://avatars.githubusercontent.com/u/24358100?v=4", - "profile": "https://github.com/ragreenburg", - "contributions": [ - "content" - ] - }, - { - "login": "stevenfukase", - "name": "stevenfukase", - "avatar_url": "https://avatars.githubusercontent.com/u/66785624?v=4", - "profile": "https://github.com/stevenfukase", - "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" - ] - }, - { - "login": "Fointard", - "name": "Fointard", - "avatar_url": "https://avatars.githubusercontent.com/u/9333398?v=4", - "profile": "https://github.com/Fointard", - "contributions": [ - "content" - ] - }, - { - "login": "rytheo", - "name": "Ryan Lowe", - "avatar_url": "https://avatars.githubusercontent.com/u/22184325?v=4", - "profile": "https://github.com/rytheo", - "contributions": [ - "code" - ] - }, - { - "login": "cuishuang", - "name": "cui fliter", - "avatar_url": "https://avatars.githubusercontent.com/u/15921519?v=4", - "profile": "http://www.dashen.tech", - "contributions": [ - "content" - ] - }, - { - "login": "luskwater", - "name": "Ron Lusk", - "avatar_url": "https://avatars.githubusercontent.com/u/42529?v=4", - "profile": "https://github.com/luskwater", - "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" - ] - }, - { - "login": "nandajavarma", - "name": "Nandaja Varma", - "avatar_url": "https://avatars.githubusercontent.com/u/2624550?v=4", - "profile": "http://nandaja.space", - "contributions": [ - "doc" - ] } ], "contributorsPerLine": 8, diff --git a/.clog.toml b/.clog.toml new file mode 100644 index 00000000..206c3b5a --- /dev/null +++ b/.clog.toml @@ -0,0 +1,4 @@ +[clog] + +repository = "https://github.com/rust-lang/rustlings" +changelog = "CHANGELOG.md" \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 73cb802d..46b1a6a8 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -4,4 +4,4 @@ tasks: vscode: extensions: - - rust-lang.rust@0.7.8 + - rust-lang.rust@0.7.8:CvNqMTgDdt3UXt+6BCDTVg== diff --git a/AUTHORS.md b/AUTHORS.md index cb997bea..a7f29bb2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -161,17 +161,6 @@ authors.
Lucas Aries

๐Ÿ–‹ -
ragreenburg

๐Ÿ–‹ -
stevenfukase

๐Ÿ–‹ -
J-S-Kim

๐Ÿ–‹ -
Fointard

๐Ÿ–‹ -
Ryan Lowe

๐Ÿ’ป -
cui fliter

๐Ÿ–‹ -
Ron Lusk

๐Ÿ–‹ - - -
Bryan Lee

๐Ÿ–‹ -
Nandaja Varma

๐Ÿ“– diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fc12506..fcc39e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,67 +1,3 @@ - -## 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) - - -#### 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) @@ -285,7 +221,7 @@ #### Features * add Option2 exercise (#290) ([86b5c08b](https://github.com/rust-lang/rustlings/commit/86b5c08b9bea1576127a7c5f599f5752072c087d)) -* add exercise for option (#282) ([135e5d47](https://github.com/rust-lang/rustlings/commit/135e5d47a7c395aece6f6022117fb20c82f2d3d4)) +* add excercise 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)) diff --git a/Cargo.lock b/Cargo.lock index 27521e7c..e536d1b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,17 @@ 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" @@ -77,14 +88,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "console" -version = "0.15.0" +name = "clicolors-control" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" +checksum = "90082ee5dcdd64dc4e9e0d37fbf3ee325419e39c0092191e0393df65518f741e" +dependencies = [ + "atty", + "lazy_static", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "console" +version = "0.7.7" +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" dependencies = [ "encode_unicode", + "lazy_static", "libc", - "once_cell", "regex", "terminal_size", "unicode-width", @@ -187,14 +228,24 @@ dependencies = [ ] [[package]] -name = "indicatif" -version = "0.16.2" +name = "hermit-abi" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d207dc617c7a380ab07ff572a6e52fa202a2a8f355860ac9c38e23f8196be1b" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ - "console", + "libc", +] + +[[package]] +name = "indicatif" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" +dependencies = [ + "console 0.14.1", "lazy_static", "number_prefix", + "parking_lot", "regex", ] @@ -218,6 +269,15 @@ 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" @@ -261,6 +321,15 @@ 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" @@ -365,15 +434,37 @@ dependencies = [ [[package]] name = "number_prefix" -version = "0.4.0" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" +checksum = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" +dependencies = [ + "num-traits", +] [[package]] -name = "once_cell" -version = "1.10.0" +name = "parking_lot" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +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", +] [[package]] name = "predicates" @@ -450,11 +541,11 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustlings" -version = "4.7.1" +version = "4.6.0" dependencies = [ "argh", "assert_cmd", - "console", + "console 0.7.7", "glob", "indicatif", "notify", @@ -479,6 +570,12 @@ 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" @@ -516,6 +613,12 @@ 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" @@ -538,10 +641,19 @@ dependencies = [ ] [[package]] -name = "toml" -version = "0.5.9" +name = "termios" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" +dependencies = [ + "libc", +] + +[[package]] +name = "toml" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index befdd6e8..4761c9a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "rustlings" -version = "4.7.1" -authors = ["mokou ", "Carol (Nichols || Goulding) "] +version = "4.6.0" +authors = ["anastasie ", "Carol (Nichols || Goulding) "] edition = "2021" [dependencies] -argh = "0.1" -indicatif = "0.16" -console = "0.15" -notify = "4.0" -toml = "0.5" -regex = "1.5" -serde= { version = "1.0", features = ["derive"] } +argh = "0.1.4" +indicatif = "0.10.3" +console = "0.7.7" +notify = "4.0.15" +toml = "0.4.10" +regex = "1.1.6" +serde = { version = "1.0.10", features = ["derive"] } [[bin]] name = "rustlings" diff --git a/README.md b/README.md index dd96a59c..5c92e2c8 100644 --- a/README.md +++ b/README.md @@ -1,194 +1,3 @@ -# 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! - -_...looking for the old, web-based version of Rustlings? Try [here](https://github.com/rust-lang/rustlings/tree/rustlings-1)_ - -Alternatively, for a first-time Rust learner, there are several other resources: - -- [The Book](https://doc.rust-lang.org/book/index.html) - The most comprehensive resource for learning Rust, but a bit theoretical sometimes. You will be using this along with Rustlings! -- [Rust By Example](https://doc.rust-lang.org/rust-by-example/index.html) - Learn Rust by solving little exercises! It's almost like `rustlings`, but online - -## 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. - -## MacOS/Linux - -Just run: - -```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/main/install.sh | bash -s mypath/ -``` - -This will install Rustlings and give you access to the `rustlings` command. Run it to get started! - -## Windows - -In PowerShell (Run as Administrator), set `ExecutionPolicy` to `RemoteSigned`: - -```ps1 -Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -``` - -Then, you can run: - -```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. - -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) - -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/rust-lang/rustlings) - -## Manually - -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 -cd rustlings -cargo install --force --path . -``` - -If there are installation errors, ensure that your toolchain is up to date. For the latest, run: - -```bash -rustup update -``` - -Then, same as above, run `rustlings` to get started. - -## Doing exercises - -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 keeps 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 -``` - -This will try to verify the completion of every exercise in a predetermined order (what we think is best for newcomers). It will also rerun automatically every time you change a file in the `exercises/` directory. If you want to only run it once, you can use: - -```bash -rustlings verify -``` - -This will do the same as watch, but it'll quit after running. - -In case you want to go by your own order, or want to only verify a single exercise, you can run: - -```bash -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: - -```bash -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 -``` - -## 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`. - -## 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. - -## 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: - -- 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). - -## Contributors โœจ - -Thanks goes to the wonderful people listed in [AUTHORS.md](./AUTHORS.md) ๐ŸŽ‰ +Please go to the [Rustlings Official GitHub](https://github.com/rust-lang/rustlings) +======= +(This is just a personal fork with *my* worked out exercises.) \ No newline at end of file diff --git a/default_out.txt b/default_out.txt new file mode 100644 index 00000000..b90d1e3a --- /dev/null +++ b/default_out.txt @@ -0,0 +1,25 @@ +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/exercises/collections/hashmap1.rs b/exercises/collections/hashmap1.rs index 64b5a7f3..899d571c 100644 --- a/exercises/collections/hashmap1.rs +++ b/exercises/collections/hashmap1.rs @@ -11,17 +11,17 @@ // Execute the command `rustlings hint hashmap1` if you need // hints. -// I AM NOT DONE - use std::collections::HashMap; fn fruit_basket() -> HashMap { - let mut basket = // TODO: declare your hash map here. + let mut basket = HashMap::new();// TODO: declare your hash map here. // Two bananas are already given for you :) basket.insert(String::from("banana"), 2); // TODO: Put more fruits in your basket here. + basket.insert(String::from("apple"), 1); + basket.insert(String::from("mango"), 2); basket } diff --git a/exercises/collections/hashmap2.rs b/exercises/collections/hashmap2.rs index 0abe19ab..87f8225f 100644 --- a/exercises/collections/hashmap2.rs +++ b/exercises/collections/hashmap2.rs @@ -12,8 +12,6 @@ // Execute the command `rustlings hint hashmap2` if you need // hints. -// I AM NOT DONE - use std::collections::HashMap; #[derive(Hash, PartialEq, Eq)] @@ -38,6 +36,11 @@ fn fruit_basket(basket: &mut HashMap) { // TODO: Put new fruits if not already present. Note that you // are not allowed to put any type of fruit that's already // present! + match fruit { + Fruit::Banana => basket.insert(fruit, 3), + Fruit::Pineapple => basket.insert(fruit, 1), + _ => None, + }; } } diff --git a/exercises/collections/vec1.rs b/exercises/collections/vec1.rs index b144fb94..c67aa52e 100644 --- a/exercises/collections/vec1.rs +++ b/exercises/collections/vec1.rs @@ -4,11 +4,12 @@ // Make me compile and pass the test! // Execute the command `rustlings hint vec1` if you need hints. -// I AM NOT DONE - fn array_and_vec() -> ([i32; 4], Vec) { let a = [10, 20, 30, 40]; // a plain array - let v = // TODO: declare your vector here with the macro for vectors + + // Either one works: + // let v = vec![10, 20, 30, 40]; + let v = a.to_vec(); (a, v) } diff --git a/exercises/collections/vec2.rs b/exercises/collections/vec2.rs index 6595e401..b6bc5c00 100644 --- a/exercises/collections/vec2.rs +++ b/exercises/collections/vec2.rs @@ -7,12 +7,11 @@ // Execute the command `rustlings hint vec2` if you need // hints. -// I AM NOT DONE - 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. + *i *= 2; // Need deref --> i is of type &mut i32 } // At this point, `v` should be equal to [4, 8, 12, 16, 20]. @@ -25,6 +24,7 @@ mod tests { #[test] fn test_vec_loop() { + // Cool use of iterator with filter and closure let v: Vec = (1..).filter(|x| x % 2 == 0).take(5).collect(); let ans = vec_loop(v.clone()); diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index f3f745ff..821309ec 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().sum::(); + let total = values.iter().fold(0.0, |a, b| a + b); total / values.len() } diff --git a/exercises/enums/enums1.rs b/exercises/enums/enums1.rs index a2223d33..2baa8f2b 100644 --- a/exercises/enums/enums1.rs +++ b/exercises/enums/enums1.rs @@ -1,11 +1,13 @@ // enums1.rs // Make me compile! Execute `rustlings hint enums1` for hints! -// I AM NOT DONE - #[derive(Debug)] enum Message { // TODO: define a few types of messages as used below + Quit, + Echo, + Move, + ChangeColor, } fn main() { diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index ec32d952..c6891ca5 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -1,11 +1,13 @@ // enums2.rs // Make me compile! Execute `rustlings hint enums2` for hints! -// I AM NOT DONE - #[derive(Debug)] enum Message { // TODO: define the different variants used below + Move{ x: i32, y: i32 }, + Echo(String), + ChangeColor(i32, i32, i32), + Quit, } impl Message { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index 178b40c4..f15beb99 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -1,10 +1,13 @@ // enums3.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE - enum Message { // TODO: implement the message variant types based on their usage below + ChangeColor((u8, u8, u8)), + Move(Point), + Echo(String), + Quit, + } struct Point { @@ -37,6 +40,12 @@ impl State { fn process(&mut self, message: Message) { // TODO: create a match expression to process the different message variants + match message { + Message::ChangeColor(color) => self.change_color(color), + Message::Move(p) => self.move_position(p), + Message::Echo(s) => self.echo(s), + Message::Quit => self.quit(), + } } } diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index c417fb26..f62c55a8 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -1,18 +1,17 @@ // 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`. Thankfully, Rust has a similar -// construct to `Option` that can be used to express error conditions. Let's use it! +// 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. // Execute `rustlings hint errors1` for hints! -// I AM NOT DONE - -pub fn generate_nametag_text(name: String) -> Option { +pub fn generate_nametag_text(name: String) -> Result { if name.len() > 0 { - Some(format!("Hi! My name is {}", name)) + Ok(format!("Hi! My name is {}", name)) } else { // Empty names aren't allowed. - None + Err("`name` was empty; it must be nonempty.".into()) } } @@ -20,6 +19,9 @@ 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/exercises/error_handling/errors2.rs b/exercises/error_handling/errors2.rs index aad3a93f..478e3e45 100644 --- a/exercises/error_handling/errors2.rs +++ b/exercises/error_handling/errors2.rs @@ -16,14 +16,12 @@ // 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. -// I AM NOT DONE - use std::num::ParseIntError; pub fn total_cost(item_quantity: &str) -> Result { let processing_fee = 1; let cost_per_item = 5; - let qty = item_quantity.parse::(); + let qty = item_quantity.parse::()?; Ok(qty * cost_per_item + processing_fee) } diff --git a/exercises/error_handling/errors3.rs b/exercises/error_handling/errors3.rs index 460ac5c4..23e3cb8e 100644 --- a/exercises/error_handling/errors3.rs +++ b/exercises/error_handling/errors3.rs @@ -4,11 +4,10 @@ // Why not? What should we do to fix it? // Execute `rustlings hint errors3` for hints! -// I AM NOT DONE - use std::num::ParseIntError; +use std::error::Error; -fn main() { +fn main() -> Result<(), Box> { let mut tokens = 100; let pretend_user_input = "8"; @@ -20,6 +19,8 @@ fn main() { tokens -= cost; println!("You now have {} tokens.", tokens); } + + Ok(()) } pub fn total_cost(item_quantity: &str) -> Result { diff --git a/exercises/error_handling/errors4.rs b/exercises/error_handling/errors4.rs index 0685c374..6fea1a7f 100644 --- a/exercises/error_handling/errors4.rs +++ b/exercises/error_handling/errors4.rs @@ -1,8 +1,6 @@ // errors4.rs // Make this test pass! Execute `rustlings hint errors4` for hints :) -// I AM NOT DONE - #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); @@ -14,6 +12,13 @@ enum CreationError { impl PositiveNonzeroInteger { fn new(value: i64) -> Result { + if value < 0 { + return Err(CreationError::Negative); + } + if value == 0 { + return Err(CreationError::Zero); + } + Ok(PositiveNonzeroInteger(value as u64)) } } diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 365a8691..b2264497 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -4,14 +4,13 @@ // 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; +use std::error::Error; -// TODO: update the return type of `main()` to make this compile. -fn main() -> Result<(), ParseIntError> { +// Boxing the errors works --> need to be able to handle two different error types +fn main() -> Result<(), Box> { let pretend_user_input = "42"; let x: i64 = pretend_user_input.parse()?; println!("output={:?}", PositiveNonzeroInteger::new(x)?); diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index 847a049a..f36b764f 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -8,8 +8,6 @@ // Make these tests pass! Execute `rustlings hint errors6` for hints :) -// I AM NOT DONE - use std::num::ParseIntError; // This is a custom error type that we will be using in `parse_pos_nonzero()`. @@ -20,7 +18,13 @@ enum ParsePosNonzeroError { } impl ParsePosNonzeroError { + fn from_creation(err: CreationError) -> ParsePosNonzeroError { + ParsePosNonzeroError::Creation(err) + } // TODO: add another error conversion function here. + fn from_parse(err: ParseIntError) -> ParsePosNonzeroError { + ParsePosNonzeroError::ParseInt(err) + } } fn parse_pos_nonzero(s: &str) @@ -28,7 +32,10 @@ fn parse_pos_nonzero(s: &str) { // TODO: change this to return an appropriate error instead of panicking // when `parse()` returns an error. - let x: i64 = s.parse().unwrap(); + let x: i64 = s.parse() + .map_err(ParsePosNonzeroError::from_parse)?; + // Need map_err to match the correct error + // then ? does the unwrap handling PositiveNonzeroInteger::new(x) .map_err(ParsePosNonzeroError::from_creation) } diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..8172a195 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,8 +1,10 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE - fn main() { call_me(); } + +fn call_me() { + println!("Found the function!") +} \ No newline at end of file diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 5721a172..cfc3cc1a 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,13 +1,11 @@ // functions2.rs // Make me compile! Execute `rustlings hint functions2` for hints :) -// I AM NOT DONE - fn main() { call_me(3); } -fn call_me(num:) { +fn call_me(num: i32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index ed5f839f..2f545795 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,10 +1,8 @@ // functions3.rs // Make me compile! Execute `rustlings hint functions3` for hints :) -// I AM NOT DONE - fn main() { - call_me(); + call_me(7); } fn call_me(num: u32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..b6af7c4b 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -4,14 +4,12 @@ // 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. -// I AM NOT DONE - fn main() { let original_price = 51; println!("Your sale price is {}", sale_price(original_price)); } -fn sale_price(price: i32) -> { +fn sale_price(price: i32) -> i32 { if is_even(price) { price - 10 } else { diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index d22aa6c8..059e9295 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,13 +1,11 @@ // functions5.rs // Make me compile! Execute `rustlings hint functions5` for hints :) -// I AM NOT DONE - fn main() { let answer = square(3); println!("The answer is {}", answer); } fn square(num: i32) -> i32 { - num * num; + num * num } diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index f93e64a0..59432e08 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -3,9 +3,7 @@ // Execute `rustlings hint generics1` for hints! -// I AM NOT DONE - fn main() { - let mut shopping_list: Vec = Vec::new(); + let mut shopping_list: Vec<&str> = Vec::new(); shopping_list.push("milk"); } diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 1501529c..8c6a5100 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -3,14 +3,12 @@ // Execute `rustlings hint generics2` for hints! -// I AM NOT DONE - -struct Wrapper { - value: u32, +struct Wrapper { + value: T, } -impl Wrapper { - pub fn new(value: u32) -> Self { +impl Wrapper { + pub fn new(value: T) -> Self { Wrapper { value } } } diff --git a/exercises/generics/generics3.rs b/exercises/generics/generics3.rs index 64dd9bc1..68d16e6f 100644 --- a/exercises/generics/generics3.rs +++ b/exercises/generics/generics3.rs @@ -10,15 +10,14 @@ // Execute 'rustlings hint generics3' for hints! -// I AM NOT DONE - -pub struct ReportCard { - pub grade: f32, +pub struct ReportCard { + pub grade: T, pub student_name: String, pub student_age: u8, } -impl ReportCard { +// Need to have Display property so that we can use the print macro +impl ReportCard { pub fn print(&self) -> String { format!("{} ({}) - achieved a grade of {}", &self.student_name, &self.student_age, &self.grade) @@ -46,7 +45,7 @@ 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, + grade: "A+", student_name: "Gary Plotter".to_string(), student_age: 11, }; diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..bcc06fdd 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,13 +1,12 @@ // if1.rs -// I AM NOT DONE - pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! // Do not use: // - another function call // - additional variables // Execute `rustlings hint if1` for hints + if a > b { a } else { b } } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index 80effbdf..4d1ab2d4 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,13 +4,14 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute the command `rustlings hint if2` if you want a hint :) -// I AM NOT DONE pub fn fizz_if_foo(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" + } else if fizzish == "fuzz" { + "bar" } else { - 1 + "baz" } } diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs index 1c4582de..3b11d4a2 100644 --- a/exercises/intro/intro1.rs +++ b/exercises/intro/intro1.rs @@ -5,8 +5,6 @@ // 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... "#); diff --git a/exercises/intro/intro2.rs b/exercises/intro/intro2.rs index 97a073f0..3b999db4 100644 --- a/exercises/intro/intro2.rs +++ b/exercises/intro/intro2.rs @@ -2,8 +2,7 @@ // Make the code print a greeting to the world. // Execute `rustlings hint intro2` for a hint. -// I AM NOT DONE - fn main() { - println!("Hello {}!"); + let x = "World"; + println!("Hello {}!", x); } diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs index 1a2bd0dd..3535a36a 100644 --- a/exercises/modules/modules1.rs +++ b/exercises/modules/modules1.rs @@ -1,15 +1,13 @@ // modules1.rs // Make me compile! Execute `rustlings hint modules1` for hints :) -// 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() { + pub fn make_sausage() { get_secret_recipe(); println!("sausage!"); } diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs index 87f0c458..8d25567b 100644 --- a/exercises/modules/modules2.rs +++ b/exercises/modules/modules2.rs @@ -3,13 +3,11 @@ // '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 statements - use self::fruits::PEAR as ??? - use self::veggies::CUCUMBER as ??? + pub use self::fruits::PEAR as fruit; + pub use self::veggies::CUCUMBER as veggie; mod fruits { pub const PEAR: &'static str = "Pear"; diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs index 8eed77df..9a38ceed 100644 --- a/exercises/modules/modules3.rs +++ b/exercises/modules/modules3.rs @@ -5,10 +5,8 @@ // 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 ??? +use std::time::{SystemTime, UNIX_EPOCH}; fn main() { match SystemTime::now().duration_since(UNIX_EPOCH) { diff --git a/exercises/move_semantics/mod.rs b/exercises/move_semantics/mod.rs index e8eecf0a..c9e61b36 100644 --- a/exercises/move_semantics/mod.rs +++ b/exercises/move_semantics/mod.rs @@ -3,4 +3,3 @@ mod move_semantics2; mod move_semantics3; mod move_semantics4; mod move_semantics5; -mod move_semantics6; diff --git a/exercises/move_semantics/move_semantics1.rs b/exercises/move_semantics/move_semantics1.rs index e2f5876d..a95f851a 100644 --- a/exercises/move_semantics/move_semantics1.rs +++ b/exercises/move_semantics/move_semantics1.rs @@ -1,12 +1,10 @@ // move_semantics1.rs // Make me compile! Execute `rustlings hint move_semantics1` for hints :) -// I AM NOT DONE - fn main() { let vec0 = Vec::new(); - let vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(vec0); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); diff --git a/exercises/move_semantics/move_semantics2.rs b/exercises/move_semantics/move_semantics2.rs index 888dc529..dae6a0c6 100644 --- a/exercises/move_semantics/move_semantics2.rs +++ b/exercises/move_semantics/move_semantics2.rs @@ -1,13 +1,12 @@ // move_semantics2.rs -// Make me compile without changing line 13 or moving line 10! +// Make me compile without changing line 13! // Execute `rustlings hint move_semantics2` for hints :) -// I AM NOT DONE - fn main() { - let vec0 = Vec::new(); + let mut vec0 = Vec::new(); - let mut vec1 = fill_vec(vec0); + let mut vec1 = vec![22, 44, 66]; + fill_vec(&mut vec0); // Do not change the following line! println!("{} has length {} content `{:?}`", "vec0", vec0.len(), vec0); @@ -17,12 +16,8 @@ fn main() { println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); } -fn fill_vec(vec: Vec) -> Vec { - let mut vec = vec; - +fn fill_vec(vec: &mut Vec) { vec.push(22); vec.push(44); vec.push(66); - - vec } diff --git a/exercises/move_semantics/move_semantics3.rs b/exercises/move_semantics/move_semantics3.rs index 43fef74f..02356426 100644 --- a/exercises/move_semantics/move_semantics3.rs +++ b/exercises/move_semantics/move_semantics3.rs @@ -3,12 +3,10 @@ // (no lines with multiple semicolons necessary!) // Execute `rustlings hint move_semantics3` for hints :) -// I AM NOT DONE - fn main() { - let vec0 = Vec::new(); + let mut vec0 = Vec::new(); - let mut vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(&mut vec0); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); @@ -17,10 +15,10 @@ fn main() { println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); } -fn fill_vec(vec: Vec) -> Vec { +fn fill_vec(vec: &mut Vec) -> Vec { vec.push(22); vec.push(44); vec.push(66); - vec + vec.to_vec() } diff --git a/exercises/move_semantics/move_semantics4.rs b/exercises/move_semantics/move_semantics4.rs index 2a23c710..c3cf03d3 100644 --- a/exercises/move_semantics/move_semantics4.rs +++ b/exercises/move_semantics/move_semantics4.rs @@ -4,12 +4,8 @@ // freshly created vector from fill_vec to its caller. // Execute `rustlings hint move_semantics4` for hints! -// I AM NOT DONE - fn main() { - let vec0 = Vec::new(); - - let mut vec1 = fill_vec(vec0); + let mut vec1 = fill_vec(); println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1); @@ -20,7 +16,7 @@ fn main() { // `fill_vec()` no longer takes `vec: Vec` as argument fn fill_vec() -> Vec { - let mut vec = vec; + let mut vec = Vec::new(); vec.push(22); vec.push(44); diff --git a/exercises/move_semantics/move_semantics5.rs b/exercises/move_semantics/move_semantics5.rs index c4704f9e..d9da5ffc 100644 --- a/exercises/move_semantics/move_semantics5.rs +++ b/exercises/move_semantics/move_semantics5.rs @@ -3,13 +3,11 @@ // adding, changing or removing any of them. // Execute `rustlings hint move_semantics5` for hints :) -// I AM NOT DONE - fn main() { let mut x = 100; let y = &mut x; - let z = &mut x; *y += 100; + let z = &mut x; *z += 1000; assert_eq!(x, 1200); } diff --git a/exercises/move_semantics/move_semantics6.rs b/exercises/move_semantics/move_semantics6.rs index 457e7ae7..f09df2ba 100644 --- a/exercises/move_semantics/move_semantics6.rs +++ b/exercises/move_semantics/move_semantics6.rs @@ -2,24 +2,22 @@ // 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); + get_char(&data); - string_uppercase(&data); + string_uppercase(data); } // Should not take ownership -fn get_char(data: String) -> char { +fn get_char(data: &String) -> char { data.chars().last().unwrap() } // Should take ownership -fn string_uppercase(mut data: &String) { - data = &data.to_uppercase(); +fn string_uppercase(mut data: String) { + data = data.to_uppercase(); println!("{}", data); } diff --git a/exercises/option/option1.rs b/exercises/option/option1.rs index 17cf4f60..1401de99 100644 --- a/exercises/option/option1.rs +++ b/exercises/option/option1.rs @@ -1,23 +1,21 @@ // option1.rs // Make me compile! Execute `rustlings hint option1` for hints -// 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()); } fn main() { - print_number(13); - print_number(99); + print_number(Some(13)); + print_number(Some(99)); - let mut numbers: [Option; 5]; + let mut numbers: [Option; 5] = [Some(0); 5]; for iter in 0..5 { let number_to_add: u16 = { ((iter * 1235) + 2) / (4 * 16) }; - numbers[iter as usize] = number_to_add; + numbers[iter as usize] = Some(number_to_add); } } diff --git a/exercises/option/option2.rs b/exercises/option/option2.rs index c6b83ece..2c596ac9 100644 --- a/exercises/option/option2.rs +++ b/exercises/option/option2.rs @@ -1,12 +1,10 @@ // option2.rs // Make me compile! Execute `rustlings hint option2` for hints -// 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 { + if let Some(word) = optional_word { println!("The word is: {}", word); } else { println!("The optional word doesn't contain anything"); @@ -19,7 +17,7 @@ fn main() { // 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); + while let Some(integer) = optional_integers_vec.pop() { + println!("current value: {}", integer.unwrap()); } } diff --git a/exercises/option/option3.rs b/exercises/option/option3.rs index 045d2acb..8fe4cfe6 100644 --- a/exercises/option/option3.rs +++ b/exercises/option/option3.rs @@ -1,8 +1,6 @@ // option3.rs // Make me compile! Execute `rustlings hint option3` for hints -// I AM NOT DONE - struct Point { x: i32, y: i32, @@ -11,7 +9,7 @@ struct Point { fn main() { let y: Option = Some(Point { x: 100, y: 200 }); - match y { + match &y { Some(p) => println!("Co-ordinates are {},{} ", p.x, p.y), _ => println!("no match"), } diff --git a/exercises/primitive_types/primitive_types1.rs b/exercises/primitive_types/primitive_types1.rs index 09121392..fc325348 100644 --- a/exercises/primitive_types/primitive_types1.rs +++ b/exercises/primitive_types/primitive_types1.rs @@ -2,8 +2,6 @@ // Fill in the rest of the line that has code missing! // No hints, there's no tricks, just get used to typing these :) -// I AM NOT DONE - fn main() { // Booleans (`bool`) @@ -12,7 +10,7 @@ fn main() { println!("Good morning!"); } - let // Finish the rest of this line like the example! Or make it be false! + let is_evening = !is_morning;// Finish the rest of this line like the example! Or make it be false! if is_evening { println!("Good evening!"); } diff --git a/exercises/primitive_types/primitive_types2.rs b/exercises/primitive_types/primitive_types2.rs index 6576a4d5..b5392b70 100644 --- a/exercises/primitive_types/primitive_types2.rs +++ b/exercises/primitive_types/primitive_types2.rs @@ -2,8 +2,6 @@ // Fill in the rest of the line that has code missing! // No hints, there's no tricks, just get used to typing these :) -// I AM NOT DONE - fn main() { // Characters (`char`) @@ -16,7 +14,7 @@ fn main() { println!("Neither alphabetic nor numeric!"); } - let // Finish this line like the example! What's your favorite character? + let your_character = 'รก';// Finish this line like the example! What's your favorite character? // Try a letter, try a number, try a special character, try a character // from a different language than your own, try an emoji! if your_character.is_alphabetic() { diff --git a/exercises/primitive_types/primitive_types3.rs b/exercises/primitive_types/primitive_types3.rs index aaa518be..3fd4732b 100644 --- a/exercises/primitive_types/primitive_types3.rs +++ b/exercises/primitive_types/primitive_types3.rs @@ -2,10 +2,8 @@ // Create an array with at least 100 elements in it where the ??? is. // Execute `rustlings hint primitive_types3` for hints! -// I AM NOT DONE - fn main() { - let a = ??? + let a = [3; 100]; if a.len() >= 100 { println!("Wow, that's a big array!"); diff --git a/exercises/primitive_types/primitive_types4.rs b/exercises/primitive_types/primitive_types4.rs index 10b553e9..d773c137 100644 --- a/exercises/primitive_types/primitive_types4.rs +++ b/exercises/primitive_types/primitive_types4.rs @@ -2,13 +2,11 @@ // Get a slice out of Array a where the ??? is so that the test passes. // Execute `rustlings hint primitive_types4` for hints!! -// I AM NOT DONE - #[test] fn slice_out_of_array() { let a = [1, 2, 3, 4, 5]; - let nice_slice = ??? + let nice_slice = &a[1..4]; assert_eq!([2, 3, 4], nice_slice) } diff --git a/exercises/primitive_types/primitive_types5.rs b/exercises/primitive_types/primitive_types5.rs index 680d8d23..85f42cfc 100644 --- a/exercises/primitive_types/primitive_types5.rs +++ b/exercises/primitive_types/primitive_types5.rs @@ -2,11 +2,9 @@ // Destructure the `cat` tuple so that the println will work. // Execute `rustlings hint primitive_types5` for hints! -// I AM NOT DONE - fn main() { let cat = ("Furry McFurson", 3.5); - let /* your pattern here */ = cat; + let (name, age) = cat; println!("{} is {} years old.", name, age); } diff --git a/exercises/primitive_types/primitive_types6.rs b/exercises/primitive_types/primitive_types6.rs index b8c9b82b..0c877aa6 100644 --- a/exercises/primitive_types/primitive_types6.rs +++ b/exercises/primitive_types/primitive_types6.rs @@ -3,13 +3,11 @@ // You can put the expression for the second element where ??? is so that the test passes. // Execute `rustlings hint primitive_types6` for hints! -// I AM NOT DONE - #[test] fn indexing_tuple() { let numbers = (1, 2, 3); // Replace below ??? with the tuple indexing syntax. - let second = ???; + let second = numbers.1; assert_eq!(2, second, "This is not the 2nd number in the tuple!") diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index 7bd3f589..2b492f95 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -8,10 +8,15 @@ // 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 - // Put your function here! // fn calculate_apple_price { +fn calculate_apple_price(num_apples: i32) -> i32 { + if num_apples > 40 { + num_apples + } else { + 2 * num_apples + } +} // Don't modify this function! #[test] diff --git a/exercises/quiz2.rs b/exercises/quiz2.rs index de0dce95..37c33a53 100644 --- a/exercises/quiz2.rs +++ b/exercises/quiz2.rs @@ -7,8 +7,6 @@ // 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! -// I AM NOT DONE - fn string_slice(arg: &str) { println!("{}", arg); } @@ -17,14 +15,14 @@ fn string(arg: String) { } 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()); + string_slice("blue"); + string("red".to_string()); + string(String::from("hi")); + string("rust is fun!".to_owned()); + string("nice weather".into()); + string(format!("Interpolation {}", "Station")); + string_slice(&String::from("abc")[0..1]); + string_slice(" hello there ".trim()); + string("Happy Monday!".to_string().replace("Mon", "Tues")); + string("mY sHiFt KeY iS sTiCkY".to_lowercase()); } diff --git a/exercises/quiz3.rs b/exercises/quiz3.rs index fae0eedb..913197fd 100644 --- a/exercises/quiz3.rs +++ b/exercises/quiz3.rs @@ -7,8 +7,6 @@ // we expect to get when we call `times_two` with a negative number. // No hints, you can do this :) -// I AM NOT DONE - pub fn times_two(num: i32) -> i32 { num * 2 } @@ -19,12 +17,12 @@ mod tests { #[test] fn returns_twice_of_positive_numbers() { - assert_eq!(times_two(4), ???); + assert_eq!(times_two(4), 8); } #[test] fn returns_twice_of_negative_numbers() { // TODO replace unimplemented!() with an assert for `times_two(-4)` - unimplemented!() + assert_eq!(times_two(-4), -8); } } diff --git a/exercises/standard_library_types/arc1.rs b/exercises/standard_library_types/arc1.rs index f60061e7..d167380c 100644 --- a/exercises/standard_library_types/arc1.rs +++ b/exercises/standard_library_types/arc1.rs @@ -32,7 +32,12 @@ fn main() { for offset in 0..8 { let child_numbers = // TODO joinhandles.push(thread::spawn(move || { - let sum: u32 = child_numbers.iter().filter(|n| *n % 8 == offset).sum(); + let mut i = offset; + let mut sum = 0; + while i < child_numbers.len() { + sum += child_numbers[i]; + i += 8; + } println!("Sum of offset {} is {}", offset, sum); })); } diff --git a/exercises/standard_library_types/box1.rs b/exercises/standard_library_types/box1.rs index f312f3d6..3f0a7c12 100644 --- a/exercises/standard_library_types/box1.rs +++ b/exercises/standard_library_types/box1.rs @@ -16,11 +16,9 @@ // // Execute `rustlings hint box1` for hints :) -// I AM NOT DONE - #[derive(PartialEq, Debug)] pub enum List { - Cons(i32, List), + Cons(i32, Box), Nil, } @@ -33,11 +31,11 @@ fn main() { } pub fn create_empty_list() -> List { - unimplemented!() + List::Nil } pub fn create_non_empty_list() -> List { - unimplemented!() + List::Cons(3, Box::new(List::Nil)) } #[cfg(test)] diff --git a/exercises/strings/strings1.rs b/exercises/strings/strings1.rs index 80902444..e43c88a4 100644 --- a/exercises/strings/strings1.rs +++ b/exercises/strings/strings1.rs @@ -2,13 +2,11 @@ // Make me compile without changing the function signature! // Execute `rustlings hint strings1` for hints ;) -// I AM NOT DONE - fn main() { let answer = current_favorite_color(); println!("My current favorite color is {}", answer); } fn current_favorite_color() -> String { - "blue" + String::from("blue") } diff --git a/exercises/strings/strings2.rs b/exercises/strings/strings2.rs index 5a2ce74a..a048f882 100644 --- a/exercises/strings/strings2.rs +++ b/exercises/strings/strings2.rs @@ -2,11 +2,9 @@ // Make me compile without changing the function signature! // Execute `rustlings hint strings2` for hints :) -// I AM NOT DONE - fn main() { let word = String::from("green"); // Try not changing this line :) - if is_a_color_word(word) { + if is_a_color_word(&word) { println!("That is a color word I know!"); } else { println!("That is not a color word I know."); diff --git a/exercises/structs/structs1.rs b/exercises/structs/structs1.rs index 6d0b2f49..87b0cf37 100644 --- a/exercises/structs/structs1.rs +++ b/exercises/structs/structs1.rs @@ -1,13 +1,12 @@ // structs1.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE - struct ColorClassicStruct { - // TODO: Something goes here + name: String, + hex: String, } -struct ColorTupleStruct(/* TODO: Something goes here */); +struct ColorTupleStruct(String, String); #[derive(Debug)] struct UnitStruct; @@ -18,8 +17,10 @@ mod tests { #[test] fn classic_c_structs() { - // TODO: Instantiate a classic c struct! - // let green = + let green = ColorClassicStruct { + name: String::from("green"), + hex: String::from("#00FF00"), + }; assert_eq!(green.name, "green"); assert_eq!(green.hex, "#00FF00"); @@ -27,8 +28,10 @@ mod tests { #[test] fn tuple_structs() { - // TODO: Instantiate a tuple struct! - // let green = + let green = ColorTupleStruct( + String::from("green"), + String::from("#00FF00"), + ); assert_eq!(green.0, "green"); assert_eq!(green.1, "#00FF00"); @@ -36,8 +39,7 @@ mod tests { #[test] fn unit_structs() { - // TODO: Instantiate a unit struct! - // let unit_struct = + let unit_struct = UnitStruct; let message = format!("{:?}s are fun!", unit_struct); assert_eq!(message, "UnitStructs are fun!"); diff --git a/exercises/structs/structs2.rs b/exercises/structs/structs2.rs index f9c6427d..b1330b78 100644 --- a/exercises/structs/structs2.rs +++ b/exercises/structs/structs2.rs @@ -1,7 +1,6 @@ // structs2.rs // Address all the TODOs to make the tests pass! -// I AM NOT DONE #[derive(Debug)] struct Order { @@ -34,7 +33,9 @@ mod tests { fn your_order() { let order_template = create_order_template(); // TODO: Create your own order using the update syntax and template above! - // let your_order = + let mut your_order = create_order_template(); + your_order.name = String::from("Hacker in Rust"); + your_order.count = 1; assert_eq!(your_order.name, "Hacker in Rust"); assert_eq!(your_order.year, order_template.year); assert_eq!(your_order.made_by_phone, order_template.made_by_phone); diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index e84f2ebc..473606fa 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -4,8 +4,6 @@ // Make the code compile and the tests pass! // If you have issues execute `rustlings hint structs3` -// I AM NOT DONE - #[derive(Debug)] struct Package { sender_country: String, @@ -16,7 +14,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!("Negative weight not allowed!") } else { Package { sender_country, @@ -26,12 +24,12 @@ impl Package { } } - fn is_international(&self) -> ??? { - // Something goes here... + fn is_international(&self) -> bool { + self.sender_country != self.recipient_country } - fn get_fees(&self, cents_per_gram: i32) -> ??? { - // Something goes here... + fn get_fees(&self, cents_per_gram: i32) -> i32 { + self.weight_in_grams * cents_per_gram } } diff --git a/exercises/tests/tests1.rs b/exercises/tests/tests1.rs index 50586a19..005731fd 100644 --- a/exercises/tests/tests1.rs +++ b/exercises/tests/tests1.rs @@ -6,12 +6,10 @@ // 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 :) -// I AM NOT DONE - #[cfg(test)] mod tests { #[test] fn you_can_assert() { - assert!(); + assert!(true); } } diff --git a/exercises/tests/tests2.rs b/exercises/tests/tests2.rs index 0d981ad1..6bfcd091 100644 --- a/exercises/tests/tests2.rs +++ b/exercises/tests/tests2.rs @@ -2,12 +2,10 @@ // 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 :) -// I AM NOT DONE - #[cfg(test)] mod tests { #[test] fn you_can_assert_eq() { - assert_eq!(); + assert_eq!(1, 1); } } diff --git a/exercises/tests/tests3.rs b/exercises/tests/tests3.rs index 3424f940..5cf291c4 100644 --- a/exercises/tests/tests3.rs +++ b/exercises/tests/tests3.rs @@ -4,8 +4,6 @@ // we expect to get when we call `is_even(5)`. // Execute `rustlings hint tests3` for hints :) -// I AM NOT DONE - pub fn is_even(num: i32) -> bool { num % 2 == 0 } @@ -16,11 +14,11 @@ mod tests { #[test] fn is_true_when_even() { - assert!(); + assert!(is_even(2)); } #[test] fn is_false_when_odd() { - assert!(); + assert!(!is_even(3)); } } diff --git a/exercises/traits/traits1.rs b/exercises/traits/traits1.rs index 15e08f24..55696e2b 100644 --- a/exercises/traits/traits1.rs +++ b/exercises/traits/traits1.rs @@ -8,14 +8,16 @@ // 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 append_bar(mut self) -> Self { + self.push_str("Bar"); + self + } } fn main() { diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index 916c3c4b..82927764 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -10,13 +10,17 @@ // No boiler plate code this time, // you can do this! -// I AM NOT DONE - trait AppendBar { fn append_bar(self) -> Self; } //TODO: Add your code here +impl AppendBar for Vec { + fn append_bar(mut self) -> Self { + self.push(String::from("Bar")); + self + } +} #[cfg(test)] mod tests { diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index d1af8311..f41da792 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -2,9 +2,7 @@ // Make me compile! // Execute the command `rustlings hint variables1` if you want a hint :) -// I AM NOT DONE - fn main() { - x = 5; + let x = 5; println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..a2add33b 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,8 @@ // variables2.rs // Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) -// I AM NOT DONE - fn main() { - let x; + let x = 0; if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 30ec48ff..7d84709d 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,10 +1,8 @@ // variables3.rs // Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) -// I AM NOT DONE - fn main() { - let x = 3; + let mut x = 3; println!("Number {}", x); x = 5; // don't change this line println!("Number {}", x); diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..7342690e 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,7 @@ // variables4.rs // Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) -// I AM NOT DONE - fn main() { - let x: i32; + let x: i32 = 7; println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 175eebb3..e31ab3f2 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,11 +1,9 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) -// I AM NOT DONE - fn main() { let number = "T-H-R-E-E"; // don't change this line println!("Spell a Number : {}", number); - number = 3; + let number = 3; println!("Number plus two is : {}", number + 2); } diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 98666914..2ad47aac 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,9 +1,7 @@ // variables6.rs // Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) -// I AM NOT DONE - -const NUMBER = 3; +const NUMBER: i32 = 3; fn main() { println!("Number {}", NUMBER); } diff --git a/info.toml b/info.toml index 54a91bfb..9430a161 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 -scope. Does it help to update the value of referent (x) immediately after +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. @@ -490,7 +490,7 @@ name = "errors1" path = "exercises/error_handling/errors1.rs" mode = "test" hint = """ -`Ok` and `Err` are one of the variants of `Result`, so what the tests are saying +`Err` is one of the variants of `Result`, so what the 2nd test is saying is that `generate_nametag_text` should return a `Result` instead of an `Option`. @@ -500,7 +500,9 @@ 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`""" + currently returns `None` + - change the first test to expect `Ok(stuff)` where it currently expects + `Some(stuff)`.""" [[exercises]] name = "errors2" diff --git a/install.ps1 b/install.ps1 index 97980c5b..32167f06 100644 --- a/install.ps1 +++ b/install.ps1 @@ -53,7 +53,7 @@ function vercomp($v1, $v2) { } $rustVersion = $(rustc --version).Split(" ")[1] -$minRustVersion = "1.56" +$minRustVersion = "1.39" 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 7d8ac90c..68b8da3a 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail echo "Let's get you set up with Rustlings!" @@ -75,21 +74,6 @@ 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 @@ -115,9 +99,9 @@ function vercomp() { } RustVersion=$(rustc --version | cut -d " " -f 2) -MinRustVersion=1.56 -vercomp "$RustVersion" $MinRustVersion || ec=$? -if [ ${ec:-0} -eq 2 ] +MinRustVersion=1.39 +vercomp $RustVersion $MinRustVersion +if [ $? -eq 2 ] then echo "ERROR: Rust version is too old: $RustVersion - needs at least $MinRustVersion" echo "Please update Rust with 'rustup update'" @@ -128,9 +112,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" diff --git a/src/main.rs b/src/main.rs index af3dffbc..32e7bba2 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.1"; +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 @@ -108,7 +108,15 @@ fn main() { } if args.nested.is_none() { - println!("\n{}\n", WELCOME); + println!(); + println!(r#" welcome to... "#); + println!(r#" _ _ _ "#); + println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#); + println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#); + println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#); + println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#); + println!(r#" |___/ "#); + println!(); } if !Path::new("info.toml").exists() { @@ -132,7 +140,8 @@ fn main() { let verbose = args.nocapture; let command = args.nested.unwrap_or_else(|| { - println!("{}\n", DEFAULT_OUT); + let text = fs::read_to_string("default_out.txt").unwrap(); + println!("{}", text); std::process::exit(0); }); match command { @@ -155,7 +164,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 { @@ -203,18 +214,54 @@ fn main() { } Subcommands::Verify(_subargs) => { - verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1)); + 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!( + "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!("\n{}\n", FENISH_LINE); + 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!"); @@ -224,7 +271,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 { @@ -261,16 +311,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) + }) } } @@ -295,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(), (0, exercises.len()), verbose) { + let failed_exercise_hint = match verify(exercises.iter(), verbose) { Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))), }; @@ -308,11 +364,15 @@ 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))); - let num_done = exercises.iter().filter(|e| e.looks_done()).count(); + .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, (num_done, exercises.len()), verbose) { + match verify(pending_exercises, verbose) { Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => { let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap(); @@ -344,64 +404,3 @@ 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... - _ _ _ - _ __ _ _ ___| |_| (_)_ __ __ _ ___ - | '__| | | / __| __| | | '_ \ / _` / __| - | | | |_| \__ \ |_| | | | | | (_| \__ \ - |_| \__,_|___/\__|_|_|_| |_|\__, |___/ - |___/"#; diff --git a/src/run.rs b/src/run.rs index eb558850..fdabb3e0 100644 --- a/src/run.rs +++ b/src/run.rs @@ -20,7 +20,7 @@ pub fn run(exercise: &Exercise, verbose: bool) -> 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)); + progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); 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)); + progress_bar.set_message(format!("Running {}...", exercise).as_str()); let result = compilation.run(); progress_bar.finish_and_clear(); diff --git a/src/verify.rs b/src/verify.rs index 6f877831..fd59fa51 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, ProgressStyle}; +use indicatif::ProgressBar; use std::env; // Verify that the provided container of Exercise objects @@ -9,18 +9,10 @@ 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>( - exercises: impl IntoIterator, - progress: (usize, usize), + start_at: impl IntoIterator, verbose: bool, ) -> Result<(), &'a Exercise> { - 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 { + 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), @@ -29,7 +21,6 @@ pub fn verify<'a>( if !compile_result.unwrap_or(false) { return Err(exercise); } - bar.inc(1); } Ok(()) } @@ -48,24 +39,25 @@ 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)); + progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); let _ = compile(exercise, &progress_bar)?; progress_bar.finish_and_clear(); + success!("Successfully compiled {}!", exercise); Ok(prompt_for_completion(exercise, None)) } // 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)); + progress_bar.set_message(format!("Compiling {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); let compilation = compile(exercise, &progress_bar)?; - progress_bar.set_message(format!("Running {}...", exercise)); + progress_bar.set_message(format!("Running {}...", exercise).as_str()); let result = compilation.run(); progress_bar.finish_and_clear(); @@ -79,6 +71,8 @@ fn compile_and_run_interactively(exercise: &Exercise) -> Result { } }; + success!("Successfully ran {}!", exercise); + Ok(prompt_for_completion(exercise, Some(output.stdout))) } @@ -86,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)); + progress_bar.set_message(format!("Testing {}...", exercise).as_str()); progress_bar.enable_steady_tick(100); let compilation = compile(exercise, &progress_bar)?; @@ -98,6 +92,7 @@ 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 { @@ -143,12 +138,6 @@ 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 { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index fc46b983..be9af965 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -125,9 +125,6 @@ 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();