Last active
May 2, 2024 14:25
-
-
Save georgematos/1288a2fc53b4081d7a3af36cc5c09ea8 to your computer and use it in GitHub Desktop.
Rust - Shadowing sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shadowing sample | |
fn main() { | |
let x = 5; | |
// shadowing x variable | |
let x = x + 1; // at this point the x was overrided with a new value | |
println!("The value of x: {x}"); | |
{ | |
// current shadowing only lives within that scope | |
let x = x * 2; | |
println!("The value of x: {x}"); | |
} | |
// the scoped shadowing dont influeces the outside x variable | |
println!("The value of x: {x}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment