assume that we have already declared a variable named guess. Shadowing lets us reuse the guess variable name (declaring a variable with the same name again) rather than forcing us to create two unique variables, such as guess_str and guess
here, the second variable overshadows the first, taking any uses of the variable name to itself until either it itself is shadowed or the scope ends. We can shadow a variable by using the same variable’s name and repeating the use of the let keyword as follows:
fn main() {
let x = 5;
let x = x + 1;
{
let x = x * 2;
println!("The value of x in the inner scope is: {x}");
// x is 12
}
println!("The value of x is: {x}");
// x is 6
}
we’re effectively creating a new variable when we use the let keyword again.
your new shadowing variable can have any datatype however the type of the shadowed variable datatype.