What is purpose of `unwrap()` if the return value is not used?

Viewed 707

I found this Rust code for getting a line 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 line variable to a line read from stdin. From my understanding, read_line() returns a Result value, which can be pattern-matched, or .unwrap() can be used to get the inner value if it is not an Err.

However, the returned value of read_line() is never used. Only the line string variable is used, but people use .unwrap() most of the time even if it is not used.

What is the purpose of unwrap() if the returned value is not used? Just to throw an error?

2 Answers
Related