I have a rust code in which it asks for the user input in a loop
use std::io;
fn main() {
let mut string = String::new();
loop {
println!("Enter a value: ");
let b = io::stdin().read_line(&mut string).expect("string");
let val: u32 = string.trim().parse().expect("Error");
println!("You typed: {:?}", val);
}
}
This code works on the initial input but on inputting values the second time it panics and exists.
thread 'main' panicked at 'Error: ParseIntError { kind: InvalidDigit }', src/main.rs:13:20 note: run with
RUST_BACKTRACE=1environment variable to display a backtrace
How do I solve this?