Function promptly::prompt [−][src]
pub fn prompt<T, S>(msg: S) -> T where
T: Promptable,
S: AsRef<str>,
Prompt until input can be parsed as T
.
Empty string input causes a re-prompt (including for String
)
except when T
is an Option
-wrapped type.
Examples
use promptly::{prompt, prompt_default}; // Prompt until a non-empty string is provided let name: String = prompt("Enter your name"); // Prompt for an optional string let name: Option<String> = prompt("Enter your name (optional)"); // Prompt for other `FromStr` types let age: u32 = prompt("Enter your age"); // Prompt for optional paths with path completion. Returns `None` if empty input. let photo: Option<PathBuf> = prompt("Enter a path to a profile picture");
Errors
If readline fails to read from stdin, this call will exit the process with an exit code of 1
.
All other errors just result in re-prompting.