I found this Rust code to get a string from stdin:
use std::io;
fn main() {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
println!("Input: {}", line);
}
io::stdin().read_line(&mut line)sets the variable lineto the string read from stdin. In my opinion, it read_line()returns a value Resultthat can be matched to a pattern, or .unwrap()can be used to get an internal value if it is not Err.
However, the return value is read_line()never used. Only a string variable is used line, but people use .unwrap()most of the time, even if it is not used.
What is the purpose unwrap()if the return value is not used? Just to throw a mistake?