Function promptly::prompt_default
source · [−]pub fn prompt_default<T, S>(msg: S, default: T) -> Result<T, ReadlineError> where
T: Promptable,
S: AsRef<str>,
Expand description
Prompt until input can be parsed as T
, returning the default
for empty input.
Examples
use promptly::prompt_default;
// Prompt Y/n with a default value when input is empty
let fallback = prompt_default("Would you like to receive marketing emails", true)?;
// Prompt for a string with default
let fav_lang = prompt_default("Enter you favorite programming language", "Rust".to_string())?;
// Prompt for other `FromStr` types
let local_ip = prompt_default("Enter your local IP", Ipv4Addr::new(127, 0, 0, 1))?;
Errors
Returns a ReadlineError
if readline fails.
Input that can’t be coerced into the specified type results in re-prompting.