1
0
Fork 0
mirror of https://github.com/notohh/rustlings.git synced 2025-11-08 05:48:11 -05:00

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
commit 9bdb0a12e4
47 changed files with 400 additions and 1681 deletions

View file

@ -1,44 +1,6 @@
// functions1.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute `rustlings hint function1` for hints :)
fn main() {
call_me();
}
// This main function is calling a function that it expects to exist, but the
// function doesn't exist. It expects this function to have the name `call_me`.
// It expects this function to not take any arguments and not return a value.
// Sounds a lot like `main`, doesn't it?

View file

@ -1,5 +1,5 @@
// functions2.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute `rustlings hint functions2` for hints :)
fn main() {
call_me(3);
@ -10,33 +10,3 @@ fn call_me(num) {
println!("Ring! Call number {}", i + 1);
}
}
// Rust requires that all parts of a function's signature have type annotations,
// but `call_me` is missing the type annotation of `num`.

View file

@ -1,5 +1,5 @@
// functions3.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute `rustlings hint functions3` for hints :)
fn main() {
call_me();
@ -10,33 +10,3 @@ fn call_me(num: i32) {
println!("Ring! Call number {}", i + 1);
}
}
// This time, the function *declaration* is okay, but there's something wrong
// with the place where we're calling the function.

View file

@ -1,5 +1,5 @@
// functions4.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute `rustlings hint functions4` for hints :)
// This store is having a sale where if the price is an even number, you get
// 10 (money unit) off, but if it's an odd number, it's 3 (money unit) less.
@ -20,25 +20,3 @@ fn sale_price(price: i32) -> {
fn is_even(num: i32) -> bool {
num % 2 == 0
}
// The error message points to line 12 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!

View file

@ -1,5 +1,5 @@
// functions5.rs
// Make me compile! Scroll down for hints :)
// Make me compile! Execute `rustlings hint functions5` for hints :)
fn main() {
let answer = square(3);
@ -9,39 +9,3 @@ fn main() {
fn square(num: i32) -> i32 {
num * num;
}
// This is a really common error that can be fixed by removing one character.
// It happens because Rust distinguishes between expressions and statements: expressions return
// a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
// We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
// They are not the same. There are two solutions:
// 1. Add a `return` ahead of `num * num;`
// 2. remove `;`, make it to be `num * num`