python_input/
lib.rs

1use std::io::{stdin, stdout, Write};
2
3/// Returns a String with what the user typed in response to the prompt.
4///
5/// # Arguments
6///
7/// * `prompt` - A &str that is printed to the console as a prompt for the user.
8///
9/// # Remarks
10///
11/// This is a convenience function that just shortens the amount of code that is
12/// necessary to recieve user input in response to a prompt, such as a question.
13pub fn input(prompt: &str) -> String {
14    print!("{}", prompt);
15    let mut input = String::new();
16
17    stdout().flush().expect("Failed to flush stdout!");
18    stdin().read_line(&mut input).expect("Failed to read line");
19
20    input.pop();
21
22    return input;
23}