How to Read from Standard Input in Rust

Cli
Read user input from the terminal in Rust using std::io::stdin and the read_line method.

Use std::io::stdin() to get a handle to standard input, then call read_line on it to populate a mutable String.

use std::io;

fn main() {
    let mut guess = String::new();
    io::stdin()
        .read_line(&mut guess)
        .expect("Failed to read line");
    println!("You guessed: {guess}");
}