Loading projects/variables/Cargo.lock 0 → 100644 +7 −0 Original line number Diff line number Diff line # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "variables" version = "0.1.0" projects/variables/Cargo.toml 0 → 100644 +6 −0 Original line number Diff line number Diff line [package] name = "variables" version = "0.1.0" edition = "2024" [dependencies] projects/variables/src/main.rs 0 → 100644 +27 −0 Original line number Diff line number Diff line fn main() { // let mut x = 5; // println!("The value of x is {x}"); // x = 6; // println!("The value of x is {x}"); let x1 = 5; let x1 = x1 + 1; { let x1 = x1 * 2; println!("The value of x1 in the inner scope is: {x1}"); } println!("The value of x1 is: {x1}"); let mut x: u32 = 1; { let mut x = x; x += 2; } println!("{x}"); // this outputs 1 because the shadowed value == 3 stays in scope of the brackets // let mut y: u32 = 1; // y = "Hello world"; // doesn't compile: you're trying to shadow a mut variable with a different data type, which is not allowed! // println!("{y}"); } Loading
projects/variables/Cargo.lock 0 → 100644 +7 −0 Original line number Diff line number Diff line # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "variables" version = "0.1.0"
projects/variables/Cargo.toml 0 → 100644 +6 −0 Original line number Diff line number Diff line [package] name = "variables" version = "0.1.0" edition = "2024" [dependencies]
projects/variables/src/main.rs 0 → 100644 +27 −0 Original line number Diff line number Diff line fn main() { // let mut x = 5; // println!("The value of x is {x}"); // x = 6; // println!("The value of x is {x}"); let x1 = 5; let x1 = x1 + 1; { let x1 = x1 * 2; println!("The value of x1 in the inner scope is: {x1}"); } println!("The value of x1 is: {x1}"); let mut x: u32 = 1; { let mut x = x; x += 2; } println!("{x}"); // this outputs 1 because the shadowed value == 3 stays in scope of the brackets // let mut y: u32 = 1; // y = "Hello world"; // doesn't compile: you're trying to shadow a mut variable with a different data type, which is not allowed! // println!("{y}"); }