feat: Refactor hint system

Hints are now accessible using the CLI subcommand `rustlings hint
<exercise name`.

BREAKING CHANGE: This fundamentally changes the way people interact with exercises.
This commit is contained in:
marisa
2019-11-11 16:51:38 +01:00
parent 627cdc07d0
commit 9bdb0a12e4
47 changed files with 400 additions and 1681 deletions

View File

@@ -1,42 +1,7 @@
// variables1.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute the command `rustlings hint variables1` if you want a hint :)
fn main() {
x = 5;
println!("x has the value {}", x);
}
// Hint: The declaration on line 5 is missing a keyword that is needed in Rust
// to create a new variable binding.

View File

@@ -1,5 +1,5 @@
// variables2.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
fn main() {
let x;
@@ -9,39 +9,3 @@ fn main() {
println!("Not ten!");
}
}
// 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 if you give x a value?
// What if you do both?
// What type should x be, anyway?
// What if x is the same type as 10? What if it's a different type?

View File

@@ -1,5 +1,5 @@
// variables3.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
fn main() {
let x = 3;
@@ -7,37 +7,3 @@ fn main() {
x = 5;
println!("Number {}", x);
}
// In Rust, variable bindings are immutable by default. But here we're trying
// to reassign a different value to x! There's a keyword we can use to make
// a variable binding mutable instead.

View File

@@ -1,45 +1,7 @@
// variables4.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
fn main() {
let x: i32;
println!("Number {}", x);
}
// 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
// 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!