The previous code was checking the threads in the order they were
created. So the progress update would be blocked on an earlier thread
even if later thread were already done.
Add to that that multiple instances of `cargo build` cannot run in
parallel, they will be serialized instead. So if the exercises needs to
be recompiled, depending on the order those `cargo build` are run,
the first update can be a long time coming.
So instead of relying on the thread terminating, use a channel to get
notified when an exercise check is done, regardless of the order they
finish in.
This allows for skipping repeating "next" when multiple exercises
are done at once, or when earlier exercises have been updated/changed
(and thus must be redone) while still working of the whole set (i.e.
the final check_all is not yet available to flag those undone exercises)
The previous code run the check on all exercises but only updates one
exercise (the first that failed) even if multiple failed. The user won't
be able to see all the failed exercises when viewing the list, and will
have to run check_all after each fixed exercise.
This change will update all the exercises so the user can see all that
failed, fix them all, and only then need run check_all again.
Some people would get stuck on this exercise, trying to understand the meaning
behind foo, fuzz, baz etc. Making the theme of the code make a little more sense
to humans should hopefully prevent people from getting confused by abstract and
non-sensical tests.
- Detect if we are in a cargo project more reliably.
(e.g. if `rustlings init` is run in the `src/` directory)
- Refuse to initialize rustlings in a non-workspace cargo project.
- Automatically populate the `workspace.members` field if `rustlings init` is
run in a workspace.
This may be considered risky, as there is no guarantee that's what the user
wanted to do. However, it is consistent with the behavior of `cargo new`.
Also, newcomers to Rust are unlikely to accidentally be in a cargo workspace,
as they won't know how to create one in the first place.
The use case for initialization in a workspace is when a workshop organizer
wants to use rustlings alongside other exerices and provide a single
repository with everything in one place.
hashbrown is already used in the standard library, but we want the
improved performance of the different hash algorithm.
Using ahash directly conveys this intent more clearly.
Exercise errors6.rs prompts the user to add a method named `from_parseint`. This commit changes the method name to the corrected snakecase format, `from_parse_int`.
In errors5.rs, there are two lines of a pattern matching block for which the order is reversed between the exercise file and the solution file. Since these lines are not changed as part of the exercise, this commit updates the exercise to make the order of the lines consistent with the solution, so that users will focus only on the lines that change between the exercise and the solution.
In the instructions for hashmaps2.rs, the last sentence of the include the phrase "these fruits", which refers to fruits that were mentioned two sentences prior.
Having a sentence in between the first sentence in which the fruits were described and a later sentence in which the phrase "these fruits" is used makes this confusing to read, since the phrase "these fruits" does not come immediately after the mention of the fruits that the phrase refers to.
This pull request expands the last sentence to explicitly refer to the fruits being mentioned, in order to add clarity about the requirement of the exercise.
Technically it's correct, but playing around with this will very quickly
throw you into having to handle `Option`s and futzing around with
`try_into`. Not really something we want to throw upon the user here.
Closes#1948.
info.toml:
```toml
[[exercises]]
name = "threads3"
path = "exercises/threads/threads3.rs"
mode = "test"
hint = """
An alternate way to handle concurrency between threads is to use
a mpsc (multiple producer, single consumer) channel to communicate.
With both a sending end and a receiving end, it's possible to
send values in one thread and receive them in another.
Multiple producers are possible by using clone() to create a duplicate
of the original sending end.
See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info.
"""
```
threads3'hint contains this link, so it should be placed in Further Information
Instead of running `rustup` on a multi-gigabyte general-purpose Linux base, use the premade devcontainers/rust:1 which closely tracks the rust toolchain releases. Rip out excess setup steps since devcontainers come with the repo checked out; just compile/update the binary.
I struggled with this exercise and didn't understand that it was looking for a summary of goals scored/conceded per team, instead of per match.
My goal here is just to clarify the language, essentially saying "the total number of goals the team scored" to indicate that we are looking for a sum.
Updated the exercise description to clarify this point.
Relates loosely to closed issue https://github.com/rust-lang/rustlings/issues/1361
Use gitattributes file to ensure script files have LF line endings. This solves a problem for users who wish to use DevContainers on Windows machines and the file has been cloned from the repository with CRLF line endings.
The advice tell us how to return as String error message. Unless I missed something, we can't even return a String error message here, so this advice is more confusing than anything and should better be removed.
Currently, the windows installation instructions download a script from the URL ps1.rustlings.cool. This URL isn't detected as a URL in some cases, which means that PowerShell tries to load the data from a local file called ps1.rustlings.cool.
This was breaking my install, and adding the https:// fixed it.
This commit makes a minor change in the wording of the description of the errors2 exercise to avoid potential confusion, changing:
"A player of the game will type in how many items they want to buy, and the `total_cost` function will calculate the total cost of the tokens."
to
"A player of the game will type in how many items they want to buy, and the `total_cost` function will calculate the total cost of the items."
This commit corrects a grammar typo in the hint of the errors1 exercise, changing from:
"`Ok` and `Err` are one of the variants of `Result`,"
to:
"`Ok` and `Err` are the two variants of `Result`,"
On windows, if `stderr` or `stdin` aren't also set to `Stdio::null()`
the `spawn()` fails with `The handle is invalid`, and `rustlings`
thinks that there's no `rustc` installed.
Previously, this would just say "missing file". Now it shows the path of the file that was missing,
which should make it easier to debug what went wrong.
Otherwise it won't actually test the change of state.message and
it would fail to check if the user missed changing state.message
This happened to me as I had a catch-all line in `match`
The existing test functions only check if a kind of fruit exists in the hashmap, but not if the amount of fruits is higher than zero. This new test function solves this.
Sets up oranda so we can get nice website things for free. Some caveats we have right now:
- Absolutely manual, I have to do `oranda build` and the deploy manually right now
- I had to pop the Readme into a new Markdown file because the first header in there was looking very strange
The existing test can be solved with the following:
```rs
while let Some(integer) = optional_integers.pop() {
assert_eq!(integer.unwrap(), range);
```
Similarly with `expect(...)`, `unwrap_or(0)`, `unwrap_or_default()`, etc. However, none of these solutions use the learning point of stacking `Option<T>`s.
The updated test can _only_ be solved by stacking `Option<T>`s:
```rs
while let Some(Some(integer)) = optional_integers.pop() {
assert_eq!(integer, cursor);
```
With the updated test, using `unwrap` or `expect` will panic when it hits the `None` value, and using `unwrap_or` or `unwrap_or_default` will cause the final `assert_eq!(cursor, 0)` to panic.
The `macros4.rs` challenge can automatically be solved by rustfmt without the user noticing.
Adding `#[rustfmt::skip]` above the `macro_rules!` line fixes this issue.
I changed the sentence that referenced the imperative implementation in iterators5.rs.
That implementation was already removed and replaced with `todo!()`
Following the discussion in #1195 this is the best I could come up with.
The issue for me (and apparently a few other learners) was that the code
needed to complete the exercise was not _missing_, but was rather there
but wrong.
In the end, what made the difference between this exercise and others
(for me) was that in this exercise I was supposed to learn what to
*expect* of an output. So I think it makes sense here to let the learner
modify the tests and not the code itself.
Fixes#1195
Signed-off-by: Daan Wynen <black.puppydog@gmx.de>
# Conflicts:
# info.toml
Theses settings files are the base needed to declare and
bootstrap development environment on codespaces
Signed-off-by: Emmanuel Roullit <emmanuel.roullit@gmail.com>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/robertlugg"><imgsrc="https://avatars0.githubusercontent.com/u/6054540?v=4?s=100"width="100px;"alt="Robert M Lugg"/><br/><sub><b>Robert M Lugg</b></sub></a><br/><ahref="#content-robertlugg"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://sazid.github.io"><imgsrc="https://avatars1.githubusercontent.com/u/2370167?v=4?s=100"width="100px;"alt="Mohammed Sazid Al Rashid"/><br/><sub><b>Mohammed Sazid Al Rashid</b></sub></a><br/><ahref="#content-sazid"title="Content">🖋</a><ahref="https://github.com/rust-lang/rustlings/commits?author=sazid"title="Code">💻</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="http://flakolefluk.dev"><imgsrc="https://avatars.githubusercontent.com/u/11986564?v=4?s=100"width="100px;"alt="Ignacio Le Fluk"/><br/><sub><b>Ignacio Le Fluk</b></sub></a><br/><ahref="#content-flakolefluk"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/hongshaoyang"><imgsrc="https://avatars.githubusercontent.com/u/19281800?v=4?s=100"width="100px;"alt="Shao Yang Hong"/><br/><sub><b>Shao Yang Hong</b></sub></a><br/><ahref="#content-hongshaoyang"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/frvannes16"><imgsrc="https://avatars.githubusercontent.com/u/3188475?v=4?s=100"width="100px;"alt="Franklin van Nes"/><br/><sub><b>Franklin van Nes</b></sub></a><br/><ahref="https://github.com/rust-lang/rustlings/commits?author=frvannes16"title="Code">💻</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/pgjbz"><imgsrc="https://avatars.githubusercontent.com/u/22059237?v=4?s=100"width="100px;"alt="Paulo Gabriel Justino Bezerra"/><br/><sub><b>Paulo Gabriel Justino Bezerra</b></sub></a><br/><ahref="#content-pgjbz"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/Mouwrice"><imgsrc="https://avatars.githubusercontent.com/u/56763273?v=4?s=100"width="100px;"alt="Maurice Van Wassenhove"/><br/><sub><b>Maurice Van Wassenhove</b></sub></a><br/><ahref="#content-Mouwrice"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/miguelraz"><imgsrc="https://avatars.githubusercontent.com/u/13056181?v=4?s=100"width="100px;"alt="Miguel Raz Guzmán Macedo"/><br/><sub><b>Miguel Raz Guzmán Macedo</b></sub></a><br/><ahref="#content-miguelraz"title="Content">🖋</a></td>
<tdalign="center"valign="top"width="12.5%"><ahref="https://github.com/gasparitiago"><imgsrc="https://avatars.githubusercontent.com/u/3237254?v=4?s=100"width="100px;"alt="Tiago De Gaspari"/><br/><sub><b>Tiago De Gaspari</b></sub></a><br/><ahref="#content-gasparitiago"title="Content">🖋</a></td>
- Raise the minimum supported Rust version to `1.87`
## 6.4.0 (2024-11-11)
### Added
- The list of exercises is now searchable by pressing `s` or `/` 🔍️ (thanks to [@frroossst](https://github.com/frroossst))
- New option `c` in the prompt to manually check all exercises ✅ (thanks to [@Nahor](https://github.com/Nahor))
- New command `check-all` to manually check all exercises ✅ (thanks to [@Nahor](https://github.com/Nahor))
- Addictive animation for showing the progress of checking all exercises. A nice showcase of parallelism in Rust ✨
- New option `x` in the prompt to reset the file of the current exercise 🔄
- Allow `dead_code` for all exercises and solutions ⚰️ (thanks to [@huss4in](https://github.com/huss4in))
- Pause input while running an exercise to avoid unexpected prompt interactions ⏸️
- Limit the maximum number of exercises to 999. Any community exercises willing to reach that limit? 🔝
### Changed
- `enums3`: Remove redundant enum definition task (thanks to [@senekor](https://github.com/senekor))
- `if2`: Make the exercise less confusing by avoiding "fizz", "fuzz", "foo", "bar" and "baz" (thanks to [@senekor](https://github.com/senekor))
- `hashmap3`: Use the method `Entry::or_default`.
- Update the state of all exercises when checking all of them (thanks to [@Nahor](https://github.com/Nahor))
- The main prompt doesn't need a confirmation with ENTER on Unix-like systems anymore.
- No more jumping back to a previous exercise when its file is changed. Use the list to jump between exercises.
- Dump the solution file after an exercise is done even if the solution's directory doesn't exist.
- Rework the footer in the list.
- Optimize the file watcher.
### Fixed
- Fix bad contrast in the list on terminals with a light theme.
## 6.3.0 (2024-08-29)
### Added
- Add the following exercise lints:
- `forbid(unsafe_code)`: You shouldn't write unsafe code in Rustlings.
- `forbid(unstable_features)`: You don't need unstable features in Rustlings and shouldn't rely on them while learning Rust.
- `forbid(todo)`: You forgot a `todo!()`.
- `forbid(empty_loop)`: This can only happen by mistake in Rustlings.
- `deny(infinite_loop)`: No infinite loops are needed in Rustlings.
- `deny(mem_forget)`: You shouldn't leak memory while still learning Rust.
- Show a link to every exercise file in the list.
- Add scroll padding in the list.
- Break the help footer of the list into two lines when the terminal width isn't big enough.
- Enable scrolling with the mouse in the list.
- `dev check`: Show the progress of checks.
- `dev check`: Check that the length of all exercise names is lower than 32.
- `dev check`: Check if exercise contains no tests and isn't marked with `test = false`.
### Changed
- The compilation time when installing Rustlings is reduced.
- Pressing `c` in the list for "continue on" now quits the list after setting the selected exercise as the current one.
- Better highlighting of the solution file after an exercise is done.
- Don't show the output of successful tests anymore. Instead, show the pretty output for tests.
- Be explicit about `q` only quitting the list and not the whole program in the list.
- Be explicit about `r` only resetting one exercise (the selected one) in the list.
- Ignore the standard output of `git init`.
- `threads3`: Remove the queue length and improve tests.
- `errors4`: Use match instead of a comparison chain in the solution.
- `functions3`: Only take `u8` to avoid using a too high number of iterations by mistake.
- `dev check`: Always check with strict Clippy (warnings to errors) when checking the solutions.
### Fixed
- Fix the error on some systems about too many open files during the final check of all exercises.
- Fix the list when the terminal height is too low.
- Restore the terminal after an error in the list.
## 6.2.0 (2024-08-09)
### Added
- Show a message before checking and running an exercise. This gives the user instant feedback and avoids confusion if the checks take too long.
- Show a helpful error message when trying to install Rustlings with a Rust version lower than the minimum one that Rustlings supports.
- Add a `README.md` file to the `solutions/` directory.
- Allow initializing Rustlings in a Cargo workspace.
- `dev check`: Check that all solutions are formatted with `rustfmt`.
### Changed
- Remove the state file and the solutions directory from the generated `.gitignore` file.
- Run the final check of all exercises in parallel.
- Small exercise improvements.
## 6.1.0 (2024-07-10)
#### Added
- `dev check`: Check that all exercises (including community ones) include at least one `TODO` comment.
- `dev check`: Check that all exercises actually fail to run (not already solved).
#### Changed
- Make enum variants more consistent between enum exercises.
- `iterators3`: Teach about the possible case of integer overflow during division.
#### Fixed
- Exit with a helpful error message on missing/unsupported terminal/TTY.
- Mark the last exercise as done.
## 6.0.1 (2024-07-04)
Small exercise improvements and fixes.
Most importantly, fixed that the exercise `clippy1` was already solved 😅
## 6.0.0 (2024-07-03)
This release is the result of a complete rewrite to deliver a ton of new features and improvements ✨
The most important changes are highlighted below.
### Installation
The installation has been simplified a lot!
To install Rustlings after installing Rust, all what you need to do now is running the following command:
```bash
cargo install rustlings
```
Yes, this means that Rustlings is now on [crates.io](https://crates.io/crates/rustlings) 🎉
You can read about the motivations of this change in [this issue](https://github.com/rust-lang/rustlings/issues/1919).
### UI/UX
- The UI is now responsive when the terminal is resized.
- The progress bar was moved to the bottom so that you can always see your progress and the current exercise to work on.
- The current exercise path is now a terminal link. It will open the exercise file in your default editor when you click on it.
- A small prompt is now always shown at the bottom. It allows you to choose an action by entering a character. For example, entering `h` will show you the hint of the current exercise.
- The comment "I AM NOT DONE!" doesn't exist anymore. Instead of needing to remove it to go to the next exercise, you need to enter `n` in the terminal.
### List mode
A new list mode was added!
You can enter it by entering `l` in the watch mode.
It offers the following features:
- Browse all exercises and see their state (pending/done).
- Filter exercises based on their state (pending/done).
- Continue at another exercise. This allows you to skip some exercises or go back to previous ones.
- Reset an exercise so you can start over and revert your changes.
### Solutions
After finishing an exercise, a solution file will be available and Rustlings will show you its path in green.
This allows you to compare your solution with an idiomatic solution and maybe learn about other ways to solve a problem.
While writing the solutions, all exercises have been polished 🌟
For example, every exercise now contains `TODO` comments to highlight what the user needs to change and where.
### LSP support out of the box
Instead of creating a `project.json` file using `rustlings lsp`, Rustlings now works with a `Cargo.toml` file out of the box.
No actions are needed to activate the language server `rust-analyzer`.
This should avoid issues related to the language server or to running exercises, especially the ones with Clippy.
### Clippy
Clippy lints are now shown on all exercises, not only the Clippy exercises 📎
Make Clippy your friend from early on 🥰
### Community Exercises
Rustlings now supports community exercises!
Do you want to create your own set of Rustlings exercises to focus on some specific topic?
Or do you want to translate the original Rustlings exercises?
Then follow the link to the guide about [community exercises](https://rustlings.rust-lang.org/community-exercises)!
## 5.6.1 (2023-09-18)
#### Changed
- Converted all exercises with assertions to test mode.
#### Fixed
- `cow1`: Reverted regression introduced by calling `to_mut` where it
shouldn't have been called, and clarified comment.
- `primitive_types3`: Require at least an array of 100 elements.
- Removed hint comments when no hint exists for the exercise.
- `as_ref_mut`: Fixed a typo in a test function name.
- `enums3`: Fixed formatting with `rustfmt`.
## 5.6.0 (2023-09-04)
#### Added
- New exercise: `if3`, teaching the user about `if let` statements.
- `hashmaps2`: Added an extra test function to check if the amount of fruits is higher than zero.
- `enums3`: Added a test for `Message`.
- `if1`: Added a test case to check equal values.
- `if3`: Added a note specifying that there are no test changes needed.
#### Changed
- Swapped the order of threads and smart pointer exercises.
- Rewrote the CLI to use `clap` - it's matured much since we switched to `argh` :)
- `structs3`: Switched from i32 to u32.
- `move_semantics`: Switched 1-4 to tests, and rewrote them to be way simpler, while still teaching about the same
concepts.
#### Fixed
- `iterators5`:
- Removed an outdated part of the hint.
- Renamed variables to use snake_case.
- `vecs2`: Updated the hint to reference the renamed loop variable.
- `enums3`: Changed message string in test so that it gets properly tested.
- `strings2`: Corrected line number in hint, then removed it (this both happened as part of this release cycle).
- `primitive_types4`: Updated hint to the correct ending index.
- `quiz1`: Removed duplicated sentence from exercise comments.
- `errors4`: Improved comment.
- `from_into`: Fixed test values.
- `cow1`: Added `.to_mut()` to distinguish from the previous test case.
- `threads2`: Updated hint text to reference the correct book heading.
#### Housekeeping
- Cleaned up the explanation paragraphs at the start of each exercise.
- Lots of Nix housekeeping that I don't feel qualified to write about!
- Improved CI workflows, we're now testing on multiple platforms at once.
## 5.5.1 (2023-05-17)
#### Fixed
- Reverted `rust-project.json` path generation due to an upstream `rust-analyzer` fix.
## 5.5.0 (2023-05-17)
#### Added
- `strings2`: Added a reference to the book chapter for reference conversion
- `lifetimes`: Added a link to the lifetimekata project
- Added a new `tests4` exercises, which teaches about testing for panics
- Added a `!` prefix command to watch mode that runs an external command
- Added a `--success-hints` option to watch mode that shows hints on exercise success
#### Changed
- `vecs2`: Renamed iterator variable bindings for clarify
- `lifetimes`: Changed order of book references
- `hashmaps2`: Clarified instructions in the todo block
- Moved lifetime exercises before test exercises (via the recommended book ordering)
- `options2`: Improved tests for layering options
- `modules2`: Added more information to the hint
#### Fixed
- `errors2`: Corrected a comment wording
- `iterators2`: Fixed a spelling mistake in the hint text
- `variables`: Wrapped the mut keyword with backticks for readability
- `move_semantics2`: Removed references to line numbers
- `cow1`: Clarified the `owned_no_mutation` comments
- `options3`: Changed exercise to panic when no match is found
- `rustlings lsp` now generates absolute paths, which should fix VSCode `rust-analyzer` usage on Windows
#### Housekeeping
- Added a markdown linter to run on GitHub actions
- Split quick installation section into two code blocks
## 5.4.1 (2023-03-10)
#### Changed
- `vecs`: Added links to `iter_mut` and `map` to README.md
- `cow1`: Changed main to tests
- `iterators1`: Formatted according to rustfmt
#### Fixed
- `errors5`: Unified undisclosed type notation
- `arc1`: Improved readability by avoiding implicit dereference
- `macros4`: Prevented auto-fix by adding `#[rustfmt::skip]`
- `cli`: Actually show correct progress percentages
## 5.4.0 (2023-02-12)
@ -28,8 +313,6 @@
- Bumped min Rust version to 1.58 in installation script
- **vec1:** Have test compare every element in a and v ([9b6c6293](https://github.com/rust-lang/rustlings/commit/9b6c629397b24b944f484f5b2bbd8144266b5695))
<aname="4.2.0"></a>
## 4.2.0 (2020-11-07)
#### Features
@ -434,8 +691,6 @@
- missing comma in test ([4fb230da](https://github.com/rust-lang/rustlings/commit/4fb230daf1251444fcf29e085cee222a91f8a37e))
- **quiz3:** Second test is for odd numbers, not even. (#553) ([18e0bfef](https://github.com/rust-lang/rustlings/commit/18e0bfef1de53071e353ba1ec5837002ff7290e6))
<aname="4.1.0"></a>
## 4.1.0 (2020-10-05)
#### Bug Fixes
@ -458,8 +713,6 @@
- **cli:** Added 'cls' command to 'watch' mode (#474) ([4f2468e1](https://github.com/rust-lang/rustlings/commit/4f2468e14f574a93a2e9b688367b5752ed96ae7b))
- **try_from_into:** Add insufficient length test (#469) ([523d18b8](https://github.com/rust-lang/rustlings/commit/523d18b873a319f7c09262f44bd40e2fab1830e5))
<aname="4.0.0"></a>
## 4.0.0 (2020-07-08)
#### Breaking Changes
@ -501,8 +754,6 @@
- **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))
<aname="3.0.0"></a>
## 3.0.0 (2020-04-11)
#### Breaking Changes
@ -525,8 +776,6 @@
- add new exercises for generics (#280) ([76be5e4e](https://github.com/rust-lang/rustlings/commit/76be5e4e991160f5fd9093f03ee2ba260e8f7229))
- Update deps to version compatable with aarch64-pc-windows (#263) ([19a93428](https://github.com/rust-lang/rustlings/commit/19a93428b3c73d994292671f829bdc8e5b7b3401))
- Update deps to version compatible with aarch64-pc-windows (#263) ([19a93428](https://github.com/rust-lang/rustlings/commit/19a93428b3c73d994292671f829bdc8e5b7b3401))
- **docs:**
- Added a necessary step to Windows installation process (#242) ([3906efcd](https://github.com/rust-lang/rustlings/commit/3906efcd52a004047b460ed548037093de3f523f))
- Fixed mangled sentence from book; edited for clarity (#266) ([ade52ff](https://github.com/rust-lang/rustlings/commit/ade52ffb739987287ddd5705944c8777705faed9))
@ -566,8 +813,6 @@
- Added traits exercises (#274 but specifically #216, which originally added
this :heart:) ([b559cdd](https://github.com/rust-lang/rustlings/commit/b559cdd73f32c0d0cfc1feda39f82b3e3583df17))
<aname="2.1.0"></a>
## 2.1.0 (2019-11-27)
#### Bug Fixes
@ -585,8 +830,6 @@
- **watch:** show hint while watching ([8143d57b](https://github.com/rust-lang/rustlings/commit/8143d57b4e88c51341dd4a18a14c536042cc009c))
<aname="2.0.0"></a>
## 2.0.0 (2019-11-12)
#### Bug Fixes
@ -607,8 +850,6 @@
- **cli:** check for rustc before doing anything ([36a033b8](https://github.com/rust-lang/rustlings/commit/36a033b87a6549c1e5639c908bf7381c84f4f425))
- **hint:** Add test for hint ([ce9fa6eb](https://github.com/rust-lang/rustlings/commit/ce9fa6ebbfdc3e7585d488d9409797285708316f))
- **watch:** clear screen before each `verify()` ([3aff590](https://github.com/rust-lang/rustlings/commit/3aff59085586c24196a547c2693adbdcf4432648))
<aname="1.5.0"></a>
## 1.5.0 (2019-11-09)
#### Bug Fixes
@ -646,8 +885,6 @@
- Added exercise for struct update syntax ([1c4c8764](https://github.com/rust-lang/rustlings/commit/1c4c8764ed118740cd4cee73272ddc6cceb9d959))
- **iterators2:** adds iterators2 exercise including config ([9288fccf](https://github.com/rust-lang/rustlings/commit/9288fccf07a2c5043b76d0fd6491e4cf72d76031))
<aname="1.4.1"></a>
### 1.4.1 (2019-08-13)
#### Bug Fixes
@ -656,8 +893,6 @@
- **option1:** Add test for prematurely passing exercise ([a750e4a1](https://github.com/rust-lang/rustlings/commit/a750e4a1a3006227292bb17d57d78ce84da6bfc6))
- **test1:** Swap assertion parameter order ([4086d463](https://github.com/rust-lang/rustlings/commit/4086d463a981e81d97781851d17db2ced290f446))
<aname="1.4.0"></a>
## 1.4.0 (2019-07-13)
#### Bug Fixes
@ -674,8 +909,6 @@
- **changelog:** Use clog for changelogs ([34e31232](https://github.com/rust-lang/rustlings/commit/34e31232dfddde284a341c9609b33cd27d9d5724))
- **iterators2:** adds iterators2 exercise including config ([9288fccf](https://github.com/rust-lang/rustlings/commit/9288fccf07a2c5043b76d0fd6491e4cf72d76031))
<aname="1.3.0"></a>
### 1.3.0 (2019-06-05)
#### Features
@ -691,16 +924,12 @@
- Fix broken link (#164, @HanKruiger)
- Remove highlighting and syntect (#167, @komaeda)
<aname="1.2.2"></a>
### 1.2.2 (2019-05-07)
#### Bug Fixes
- Reverted `--nocapture` flag since it was causing tests to pass unconditionally
<aname="1.2.1"></a>
### 1.2.1 (2019-04-22)
#### Bug Fixes
@ -708,8 +937,6 @@
- Fix the `--nocapture` feature (@komaeda)
- Provide a nicer error message for when you're in the wrong directory
<aname="1.2.0"></a>
### 1.2.0 (2019-04-22)
#### Features
@ -717,8 +944,6 @@
- Add errors to exercises that compile without user changes (@yvan-sraka)
- Use --nocapture when testing, enabling `println!` when running (@komaeda)
<aname="1.1.1"></a>
### 1.1.1 (2019-04-14)
#### Bug fixes
@ -731,8 +956,6 @@
- Fix links by deleting book version (@diodfr, #142)
- Canonicalize paths to fix path matching (@cjpearce, #143)
<aname="1.1.0"></a>
### 1.1.0 (2019-03-20)
- errors2.rs: update link to Rust book (#124)
@ -742,16 +965,12 @@
- Give a warning when Rustlings isn't run from the right directory (#123)
- Verify that rust version is recent enough to install Rustlings (#131)
<aname="1.0.1"></a>
### 1.0.1 (2019-03-06)
- Adds a way to install Rustlings in one command (`curl -L https://git.io/rustlings | bash`)
- Makes `rustlings watch` react to create file events (@shaunbennett, #117)
- Reworks the exercise management to use an external TOML file instead of just listing them in the code
First off, thanks for taking the time to contribute!! ❤️
First off, thanks for taking the time to contribute! ❤️
### Quick Reference
## Quick Reference
I want to...
I want to …
_add an exercise! ➡️ [read this](#addex) and then [open a Pull Request](#prs)_
- _report a bug!_ ➡️ [open an issue](#issues)
- _fix a bug!_ ➡️ [open a pull request](#pull-requests)
- _implement a new feature!_ ➡️ [open an issue to discuss it first, then a pull request](#issues)
- _add an exercise!_ ➡️ [read this](#adding-an-exercise)
- _update an outdated exercise!_ ➡️ [open a pull request](#pull-requests)
_update an outdated exercise! ➡️ [open a Pull Request](#prs)_
_report a bug! ➡️ [open an Issue](#issues)_
_fix a bug! ➡️ [open a Pull Request](#prs)_
_implement a new feature! ➡️ [open an Issue to discuss it first, then a Pull Request](#issues)_
<aname="#src"></a>
### Working on the source code
`rustlings` is basically a glorified `rustc` wrapper. Therefore the source code
isn't really that complicated since the bulk of the work is done by `rustc`.
`src/main.rs` contains a simple `argh` CLI that connects to most of the other source files.
<aname="addex"></a>
### Adding an exercise
The first step is to add the exercise! Name the file `exercises/yourTopic/yourTopicN.rs`, make sure to
put in some helpful links, and link to sections of the book in `exercises/yourTopic/README.md`.
Next make sure it runs with `rustlings`. The exercise metadata is stored in `info.toml`, under the `exercises` array. The order of the `exercises` array determines the order the exercises are run by `rustlings verify` and `rustlings watch`.
Add the metadata for your exercise in the correct order in the `exercises` array. If you are unsure of the correct ordering, add it at the bottom and ask in your pull request. The exercise metadata should contain the following:
```diff
...
+ [[exercises]]
+ name = "yourTopicN"
+ path = "exercises/yourTopic/yourTopicN.rs"
+ mode = "compile"
+ hint = """
+ Some kind of useful hint for your exercise."""
...
```
The `mode` attribute decides whether Rustlings will only compile your exercise, or compile and test it. If you have tests to verify in your exercise, choose `test`, otherwise `compile`. If you're working on a Clippy exercise, use `mode = "clippy"`.
That's all! Feel free to put up a pull request.
<aname="issues"></a>
### Issues
## Issues
You can open an issue [here](https://github.com/rust-lang/rustlings/issues/new).
If you're reporting a bug, please include the output of the following commands:
- `rustc --version`
- `cargo --version`
- `rustlings --version`
- `ls -la`
- Your OS name and version
<aname="prs"></a>
### Pull Requests
## Pull Requests
Opening a pull request is as easy as forking the repository and committing your
changes. There's a couple of things to watch out for:
You are welcome to open a pull request, but unless it is small and trivial, **please open an issue to discuss your idea first** 🙏🏼
#### Write correct commit messages
Opening a pull request is as easy as forking the repository and committing your changes.
If you need any help with it or face any Git related problems, don't hesitate to ask for help 🤗
We follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.4/)
specification.
This means that you have to format your commit messages in a specific way. Say
you're working on adding a new exercise called `foobar1.rs`. You could write
the following commit message:
It may take time to review your pull request.
Please be patient 😇
```
feat: add foobar1.rs exercise
When updating an exercise, check if its solution needs to be updated.
## Adding An Exercise
- Name the file `exercises/yourTopic/yourTopicN.rs`.
- Make sure to put in some helpful links, and link to sections of The Book in `exercises/yourTopic/README.md`.
- In the exercise, add a `// TODO: …` comment where user changes are required.
- Add a solution at `solutions/yourTopic/yourTopicN.rs` with comments explaining it.
- Add the [metadata for your exercise](#exercise-metadata) in the `rustlings-macros/info.toml` file.
- Make sure your exercise runs with `rustlings run yourTopicN`.
- [Open a pull request](#pull-requests).
### Exercise Metadata
The exercise metadata should contain the following:
```toml
[[exercises]]
name = "yourTopicN"
dir = "yourTopic"
hint = """
A useful (multi-line) hint for your exercise.
Include links to a section in The Book or a documentation page."""
```
If you're just fixing a bug, please use the `fix` type:
```
fix(verify): make sure verify doesn't self-destruct
```
The scope within the brackets is optional, but should be any of these:
- `installation` (for the installation script)
- `cli` (for general CLI changes)
- `verify` (for the verification source file)
- `watch` (for the watch functionality source)
- `run` (for the run functionality source)
- `EXERCISENAME` (if you're changing a specific exercise, or set of exercises,
substitute them here)
When the commit also happens to close an existing issue, link it in the message
body:
```
fix: update foobar
closes #101029908
```
If you're doing simple changes, like updating a book link, use `chore`:
```
chore: update exercise1.rs book link
```
If you're updating documentation, use `docs`:
```
docs: add more information to Readme
```
If, and only if, you're absolutely sure you want to make a breaking change
(please discuss this beforehand!), add an exclamation mark to the type and
explain the breaking change in the message body:
```
fix!: completely change verification
BREAKING CHANGE: This has to be done because lorem ipsum dolor
```
#### Pull Request Workflow
Once you open a Pull Request, it may be reviewed or labeled (or both) until
the maintainers accept your change. Please be patient, it may take some time
for this to happen!
If your exercise doesn't contain any test, add `test = false` to the exercise metadata.
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!
Small exercises to get you used to reading and writing [Rust](https://www.rust-lang.org) code - _Recommended in parallel to reading [the official Rust book](https://doc.rust-lang.org/book) 📚️_
_...looking for the old, web-based version of Rustlings? Try [here](https://github.com/rust-lang/rustlings/tree/rustlings-1)_
Visit the **website** for a demo, info about setup and more:
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.
To install Rustlings. Same as on MacOS/Linux, you will have access to the `rustlings` command after it. Keep in mind that this works best in PowerShell, and any other terminals may give you errors.
If you get a permission denied message, you might have to exclude the directory where you cloned Rustlings in your antivirus.
## Browser
[Run on Repl.it](https://repl.it/github/rust-lang/rustlings)
[](https://gitpod.io/#https://github.com/rust-lang/rustlings)
## Manually
Basically: Clone the repository at the latest tag, run `cargo install --path .`.
```bash
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.4.0)
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/<topic>`. 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`
Run the command `rustlings lsp` which will generate a `rust-project.json` at the root of the project, this allows [rust-analyzer](https://rust-analyzer.github.io/) to parse each exercise.
## Continuing On
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 are 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!
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md).
Development-focused discussion about Rustlings happens in the [**rustlings** stream](https://rust-lang.zulipchat.com/#narrow/stream/334454-rustlings)
on the [Rust Project Zulip](https://rust-lang.zulipchat.com). Feel free to start a new thread there
if you have ideas or suggestions!
## Contributors ✨
Thanks goes to the wonderful people listed in [AUTHORS.md](./AUTHORS.md) 🎉
Rust allows you to define types called "enums" which enumerate possible values.
Enums are a feature in many languages, but their capabilities differ in each language. Rust’s enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell.
Enums are a feature in many languages, but their capabilities differ in each language. Rust's enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell.
Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration.
Most errors aren’t serious enough to require the program to stop entirely.
Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to.
For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process.
Most errors aren't serious enough to require the program to stop entirely.
Sometimes, when a function fails, it's for a reason that you can easily interpret and respond to.
For example, if you try to open a file and that operation fails because the file doesn't exist, you might want to create the file instead of terminating the process.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.