Skip to content

Commit 89c7364

Browse files
author
fmoko
authored
Add variables5 to introduce shadowing (#264)
Add variables5 to introduce shadowing
2 parents 19a9342 + 0c73609 commit 89c7364

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

exercises/variables/variables5.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// variables5.rs
2+
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
3+
4+
// I AM NOT DONE
5+
6+
fn main() {
7+
let number = "3";
8+
println!("Number {}", number);
9+
number = 3;
10+
println!("Number {}", number);
11+
}

info.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ value. We can't print out something that isn't there; try giving x a value!
4141
This is an error that can cause bugs that's very easy to make in any
4242
programming language -- thankfully the Rust compiler has caught this for us!"""
4343

44+
[[exercises]]
45+
name = "variables5"
46+
path = "exercises/variables/variables5.rs"
47+
mode = "compile"
48+
hint = """
49+
In variables3 we already learned how to make an immutable variable mutable
50+
using a special keyword. Unfortunately this doesn't help us much in this exercise
51+
because we want to assign a different typed value to an existing variable. Sometimes
52+
you may also like to reuse existing variable names because you are just converting
53+
values to different types like in this exercise.
54+
Fortunately Rust has a powerful solution to this problem: 'Shadowing'!
55+
You can read more about 'Shadowing' in the book's section 'Variables and Mutability'.
56+
Try to solve this exercise afterwards using this technique."""
57+
4458
# IF
4559

4660
[[exercises]]

0 commit comments

Comments
 (0)