varables and shadowing

This commit is contained in:
Tahinli 2023-04-12 03:55:25 +03:00
parent 4a437ba5dd
commit a9dc0fc610
2 changed files with 31 additions and 0 deletions

8
variables/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

23
variables/src/main.rs Normal file
View file

@ -0,0 +1,23 @@
fn main() {
println!("Hello, world!");
let mut x = 5;
println!("X = {x}");
x = 6;
println!("X = {x}");
let shadowed = 5;
let shadowed = shadowed + 2; //overshadow
{
let shadowed = shadowed + 13; //overshadow in scope
println!("Shadowed in this scope is = {shadowed}");
}
println!("Shadowed in there is = {shadowed}");
let str = "Hello There";
println!("Str = {}", str);
let str = str.len(); //overshadow with different type
println!("Str = {}", str);
}