diff options
| author | fmoko <mokou@posteo.de> | 2020-01-14 23:32:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-14 23:32:45 +0100 |
| commit | 89c73647f1cc0b8aa9e2e3d32a1de6f37327122e (patch) | |
| tree | 07178cb70d801334aaedc6164b17b17ab6619913 | |
| parent | 19a93428b3c73d994292671f829bdc8e5b7b3401 (diff) | |
| parent | 0c73609e6f2311295e95d6f96f8c747cfc4cba03 (diff) | |
Add variables5 to introduce shadowing (#264)
Add variables5 to introduce shadowing
| -rw-r--r-- | exercises/variables/variables5.rs | 11 | ||||
| -rw-r--r-- | info.toml | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs new file mode 100644 index 0000000..47a68a5 --- /dev/null +++ b/exercises/variables/variables5.rs @@ -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); +} @@ -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 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 [[exercises]] |
