Function console_utils::input
source · pub fn input(before: &str, allow_empty: bool, new_line: bool) -> Option<String>Expand description
Reads user input from the console.
This function prompts the user with a message (before) and reads a line of input from the
console. The input can be empty unless allow_empty is set to false. If new_line is set
to true, a newline character will be printed after the prompt.
Arguments
before- The text to display before prompting for input.allow_empty- If true, allows the input to be empty.new_line- If true, adds a newline character after the prompt.
Returns
Returns an Option<String> containing the user’s input or None if the input is empty and
allow_empty is false.
Example
use console_utils::input;
let user_input = input("Enter something: ", false, false);
match user_input {
Some(value) => println!("You entered: {}", value),
None => println!("Input is empty."),
}