mk_console 0.1.0

Personal library for handling rust console IO.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use std::io::{Write, stdout, stdin};

pub fn read_string(preceding: Option<&str>) -> std::io::Result<String> {
    if let Some(preceding) = preceding {
        stdout().write(
            format!("{}", preceding).as_bytes()
        )?;
        stdout().flush()?;
    }

    let mut buffer = String::new();
    stdin().read_line(&mut buffer)?;
    let input = buffer.trim();
    Ok(input.to_string())
}