DEV Community

Discussion on: My first impressions of Rust

Collapse
 
l0uisc profile image
Louis Cloete

Shadowing is most useful when you are parsing keyboard input:

use std::io;

let mut num = String::new()
io::stdin().read_line(&mut num).expect("Failed to read line");
let num: usize = num.trim().parse().expect("Failed to parse number");
// Continue to use num as immutable usize. The mutable String is now not accessible any more.