Function console_utils::input::input
source · pub fn input<T>(before: &str, allow_empty: bool) -> Option<T>where
T: FromStr,
T::Err: Debug,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. Add here\nfor a new line.allow_empty- If true, allows the input to be empty.
Returns
Returns an Option<T> containing the user’s input converted to the specified type,
or None if the input is empty and allow_empty is true.
Example
use console_utils::input::input;
let user_input = input::<String>("Enter something: ", false);
match user_input {
Some(value) => println!("You entered: {}", value),
None => panic!("The Input cannot be None, allow_empty is false."),
}