~evan-hoose/Snippets

ref: b3bbb28e5098fe466cea3b33f1e2d0bcb946610f Snippets/read_in.rs -rw-r--r-- 411 bytes
b3bbb28eEvan On branch master 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::io;

fn read_in() {
    let mut buffer = String::new();
    let stdin = io::stdin();

    //pronounced "Red" input.
    let read_input = stdin.read_line(&mut buffer);

    //If line reading fails, try again.
    if read_input.is_err() {
        println!("Unable to read in what you wrote. Please restart.");
        read_date();
    }

    let read_input = read_input.trim();

    return read_input

}