mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-29 16:44:18 -05:00
Add variables5 to introduce shadowing (#264)
Add variables5 to introduce shadowing
This commit is contained in:
commit
89c73647f1
2 changed files with 25 additions and 0 deletions
11
exercises/variables/variables5.rs
Normal file
11
exercises/variables/variables5.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// variables5.rs
|
||||||
|
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
|
||||||
|
|
||||||
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let number = "3";
|
||||||
|
println!("Number {}", number);
|
||||||
|
number = 3;
|
||||||
|
println!("Number {}", number);
|
||||||
|
}
|
14
info.toml
14
info.toml
|
@ -41,6 +41,20 @@ 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
|
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!"""
|
programming language -- thankfully the Rust compiler has caught this for us!"""
|
||||||
|
|
||||||
|
[[exercises]]
|
||||||
|
name = "variables5"
|
||||||
|
path = "exercises/variables/variables5.rs"
|
||||||
|
mode = "compile"
|
||||||
|
hint = """
|
||||||
|
In variables3 we already learned how to make an immutable variable mutable
|
||||||
|
using a special keyword. Unfortunately this doesn't help us much in this exercise
|
||||||
|
because we want to assign a different typed value to an existing variable. Sometimes
|
||||||
|
you may also like to reuse existing variable names because you are just converting
|
||||||
|
values to different types like in this exercise.
|
||||||
|
Fortunately Rust has a powerful solution to this problem: 'Shadowing'!
|
||||||
|
You can read more about 'Shadowing' in the book's section 'Variables and Mutability'.
|
||||||
|
Try to solve this exercise afterwards using this technique."""
|
||||||
|
|
||||||
# IF
|
# IF
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
|
|
Loading…
Reference in a new issue