mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-26 00:11:49 +02:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b79691d5e | ||
|
|
615ce32798 | ||
|
|
31c25ebb50 | ||
|
|
f4acb888a6 | ||
|
|
8143d57b4e | ||
|
|
a40ad092e9 | ||
|
|
b565c4d3e7 | ||
|
|
e9a835c1c0 | ||
|
|
cf38f03459 | ||
|
|
4c5189df2b | ||
|
|
a09f684f05 | ||
|
|
8cc5af121c | ||
|
|
c42c3b2101 | ||
|
|
fda5a47069 | ||
|
|
57a837bde6 | ||
|
|
ded2c034ba |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,3 +1,21 @@
|
||||
<a name="2.1.0"></a>
|
||||
## 2.1.0 (2019-11-27)
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
* add line numbers in several exercises and hints ([b565c4d3](https://github.com/rust-lang/rustlings/commit/b565c4d3e74e8e110bef201a082fa1302722a7c3))
|
||||
* **arc1:** Fix some words in the comment ([c42c3b21](https://github.com/rust-lang/rustlings/commit/c42c3b2101df9164c8cd7bb344def921e5ba3e61))
|
||||
* **enums:** Add link to chapter on pattern syntax (#242) ([615ce327](https://github.com/rust-lang/rustlings/commit/615ce3279800c56d89f19d218ccb7ef576624feb))
|
||||
* **primitive_types4:**
|
||||
* update outdated hint ([4c5189df](https://github.com/rust-lang/rustlings/commit/4c5189df2bdd9a231f6b2611919ba5aa14da0d3f))
|
||||
* update outdated comment ([ded2c034](https://github.com/rust-lang/rustlings/commit/ded2c034ba93fa1e3c2c2ea16b83abc1a57265e8))
|
||||
* **strings2:** update line number in hint ([a09f684f](https://github.com/rust-lang/rustlings/commit/a09f684f05c58d239a6fc59ec5f81c2533e8b820))
|
||||
* **variables1:** Correct wrong word in comment ([fda5a470](https://github.com/rust-lang/rustlings/commit/fda5a47069e0954f16a04e8e50945e03becb71a5))
|
||||
|
||||
#### Features
|
||||
|
||||
* **watch:** show hint while watching ([8143d57b](https://github.com/rust-lang/rustlings/commit/8143d57b4e88c51341dd4a18a14c536042cc009c))
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
## 2.0.0 (2019-11-12)
|
||||
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -629,7 +629,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustlings"
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
dependencies = [
|
||||
"assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "rustlings"
|
||||
version = "2.0.0"
|
||||
version = "2.1.0"
|
||||
authors = ["Marisa <mokou@posteo.de>", "Carol (Nichols || Goulding) <carol.nichols@gmail.com"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ Basically: Clone the repository, checkout to the latest tag, run `cargo install`
|
||||
```bash
|
||||
git clone https://github.com/rust-lang/rustlings
|
||||
cd rustlings
|
||||
git checkout tags/2.0.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest)
|
||||
git checkout tags/2.1.0 # or whatever the latest version is (find out at https://github.com/rust-lang/rustlings/releases/latest)
|
||||
cargo install --force --path .
|
||||
```
|
||||
|
||||
|
||||
@@ -5,3 +5,4 @@ Rust allows you to define a type called `enums` which allow you to enumerate pos
|
||||
#### Book Sections
|
||||
|
||||
- [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html)
|
||||
- [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// move_semantics2.rs
|
||||
// Make me compile without changing line 10!
|
||||
// Make me compile without changing line 13!
|
||||
// Execute `rustlings hint move_semantics2` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// primitive_types4.rs
|
||||
// Get a slice out of Array a where the ??? is so that the `if` statement
|
||||
// returns true. Execute `rustlings hint primitive_types4` for hints!!
|
||||
// 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 main() {
|
||||
fn slice_out_of_array() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
let nice_slice = ???
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// arc1.rs
|
||||
// Make this code compile by filling in a value for `shared_numbers` where the
|
||||
// TODO comment is and creating an initial binding for `child_numbers`
|
||||
// TODO comment is and create an initial binding for `child_numbers`
|
||||
// somewhere. Try not to create any copies of the `numbers` Vec!
|
||||
// Execute `rustlings help arc1` for hints :)
|
||||
// Execute `rustlings hint arc1` for hints :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// threads1.rs
|
||||
// Make this compile! Execute `rustlings hint threads1` for hints :)
|
||||
// The idea is the thread spawned on line 19 is completing jobs while the main thread is
|
||||
// The idea is the thread spawned on line 21 is completing jobs while the main thread is
|
||||
// monitoring progress until 10 jobs are completed. If you see 6 lines
|
||||
// of "waiting..." and the program ends without timing out when running,
|
||||
// you've got it :)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// About this `I AM NOT DONE` thing:
|
||||
// We sometimes encourage you to keep trying things on a given exercise,
|
||||
// even after you already figured it out. If you got everything working and
|
||||
// feel ready for the next exercise, you the `I AM NOT DONE` comment below.
|
||||
// feel ready for the next exercise, remove the `I AM NOT DONE` comment below.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
|
||||
22
info.toml
22
info.toml
@@ -5,7 +5,7 @@ name = "variables1"
|
||||
path = "exercises/variables/variables1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Hint: The declaration on line 5 is missing a keyword that is needed in Rust
|
||||
Hint: The declaration on line 12 is missing a keyword that is needed in Rust
|
||||
to create a new variable binding."""
|
||||
|
||||
[[exercises]]
|
||||
@@ -15,7 +15,7 @@ mode = "compile"
|
||||
hint = """
|
||||
The compiler message is saying that Rust cannot infer the type that the
|
||||
variable binding `x` has with what is given here.
|
||||
What happens if you annotate line 5 with a type annotation?
|
||||
What happens if you annotate line 7 with a type annotation?
|
||||
What if you give x a value?
|
||||
What if you do both?
|
||||
What type should x be, anyway?
|
||||
@@ -36,7 +36,7 @@ path = "exercises/variables/variables4.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
Oops! In this exercise, we have a variable binding that we've created on
|
||||
line 5, and we're trying to use it on line 6, but we haven't given it a
|
||||
line 7, and we're trying to use it on line 8, but we haven't given it a
|
||||
value. We can't print out something that isn't there; try giving x a value!
|
||||
This is an error that can cause bugs that's very easy to make in any
|
||||
programming language -- thankfully the Rust compiler has caught this for us!"""
|
||||
@@ -90,7 +90,7 @@ name = "functions4"
|
||||
path = "exercises/functions/functions4.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
The error message points to line 12 and says it expects a type after the
|
||||
The error message points to line 14 and says it expects a type after the
|
||||
`->`. This is where the function's return type should be-- take a look at
|
||||
the `is_even` function for an example!"""
|
||||
|
||||
@@ -152,8 +152,8 @@ https://doc.rust-lang.org/book/ch04-03-slices.html
|
||||
and use the starting and ending indices of the items in the Array
|
||||
that you want to end up in the slice.
|
||||
|
||||
If you're curious why the right hand of the `==` comparison does not
|
||||
have an ampersand for a reference since the left hand side is a
|
||||
If you're curious why the first argument of `assert_eq!` does not
|
||||
have an ampersand for a reference since the second argument is a
|
||||
reference, take a look at the Deref coercions section of the book:
|
||||
https://doc.rust-lang.org/book/ch15-02-deref.html"""
|
||||
|
||||
@@ -214,7 +214,7 @@ mode = "compile"
|
||||
hint = """
|
||||
Yes, it would be really easy to fix this by just changing the value bound to `word` to be a
|
||||
string slice instead of a `String`, wouldn't it?? There is a way to add one character to line
|
||||
6, though, that will coerce the `String` into a string slice."""
|
||||
9, though, that will coerce the `String` into a string slice."""
|
||||
|
||||
# TEST 2
|
||||
|
||||
@@ -365,8 +365,8 @@ name = "move_semantics1"
|
||||
path = "exercises/move_semantics/move_semantics1.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 11,
|
||||
right? The fix for this is going to be adding one keyword, and the addition is NOT on line 11
|
||||
So you've got the "cannot borrow immutable local variable `vec1` as mutable" error on line 13,
|
||||
right? The fix for this is going to be adding one keyword, and the addition is NOT on line 13
|
||||
where the error is."""
|
||||
|
||||
[[exercises]]
|
||||
@@ -375,8 +375,8 @@ path = "exercises/move_semantics/move_semantics2.rs"
|
||||
mode = "compile"
|
||||
hint = """
|
||||
So `vec0` is being *moved* into the function `fill_vec` when we call it on
|
||||
line 7, which means it gets dropped at the end of `fill_vec`, which means we
|
||||
can't use `vec0` again on line 10 (or anywhere else in `main` after the
|
||||
line 10, which means it gets dropped at the end of `fill_vec`, which means we
|
||||
can't use `vec0` again on line 13 (or anywhere else in `main` after the
|
||||
`fill_vec` call for that matter). We could fix this in a few ways, try them
|
||||
all!
|
||||
1. Make another, separate version of the data that's in `vec0` and pass that
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -6,9 +6,12 @@ use notify::DebouncedEvent;
|
||||
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::mpsc::channel;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
mod exercise;
|
||||
@@ -108,6 +111,26 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
|
||||
let failed_exercise_hint = Arc::clone(failed_exercise_hint);
|
||||
println!("Type 'hint' to get help");
|
||||
thread::spawn(move || loop {
|
||||
let mut input = String::new();
|
||||
match io::stdin().read_line(&mut input) {
|
||||
Ok(_) => {
|
||||
if input.trim().eq("hint") {
|
||||
if let Some(hint) = &*failed_exercise_hint.lock().unwrap() {
|
||||
println!("{}", hint);
|
||||
}
|
||||
} else {
|
||||
println!("unknown command: {}", input);
|
||||
}
|
||||
}
|
||||
Err(error) => println!("error reading command: {}", error),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
/* Clears the terminal with an ANSI escape code.
|
||||
Works in UNIX and newer Windows terminals. */
|
||||
@@ -121,8 +144,11 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
|
||||
|
||||
clear_screen();
|
||||
let _ignored = verify(exercises.iter());
|
||||
let verify_result = verify(exercises.iter());
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = Arc::new(Mutex::new(verify_result.map_err(to_owned_hint).err()));
|
||||
spawn_watch_shell(&failed_exercise_hint);
|
||||
loop {
|
||||
match rx.recv() {
|
||||
Ok(event) => match event {
|
||||
@@ -133,7 +159,9 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
|
||||
.iter()
|
||||
.skip_while(|e| !filepath.ends_with(&e.path));
|
||||
clear_screen();
|
||||
let _ignored = verify(pending_exercises);
|
||||
let verify_result = verify(pending_exercises);
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
*failed_exercise_hint = verify_result.map_err(to_owned_hint).err();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -2,14 +2,14 @@ use crate::exercise::{Exercise, Mode, State};
|
||||
use console::{style, Emoji};
|
||||
use indicatif::ProgressBar;
|
||||
|
||||
pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<(), ()> {
|
||||
pub fn verify<'a>(start_at: impl IntoIterator<Item = &'a Exercise>) -> Result<(), &'a Exercise> {
|
||||
for exercise in start_at {
|
||||
let is_done = match exercise.mode {
|
||||
Mode::Test => compile_and_test_interactively(&exercise)?,
|
||||
Mode::Compile => compile_only(&exercise)?,
|
||||
let compile_result = match exercise.mode {
|
||||
Mode::Test => compile_and_test_interactively(&exercise),
|
||||
Mode::Compile => compile_only(&exercise),
|
||||
};
|
||||
if !is_done {
|
||||
return Err(());
|
||||
if !compile_result.unwrap_or(false) {
|
||||
return Err(exercise);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user