Let variables shadow same name variables in the same block!

I believe they're talking about this sort of pattern, which is somewhat popular in Rust. (clearly opinions differ here, but the strong type system helps avoid mistakes.)

fn main() {
    let mut num: String = " 12345 ".to_string();
    
    num.retain(|c| c.is_ascii_digit());
    
    let num: u32 = num.parse().unwrap();
    
    println!("num: {}", num);
}

on the playground

5 Likes