Function promptly::prompt_opt
source · [−]pub fn prompt_opt<T, S>(msg: S) -> Result<Option<T>, ReadlineError> where
T: Promptable,
S: AsRef<str>,
Expand description
Prompt until input can be parsed as T
, returning None
for empty input.
Empty string input results in None
Examples
use promptly::prompt_opt;
// Prompt for an optional string
let name: Option<String> = prompt_opt("Enter your name (optional)")?;
// Prompt for optional paths with path completion. Returns `None` if empty input.
let photo: Option<PathBuf> = prompt_opt("Enter a path to a profile picture")?;
Errors
Returns a ReadlineError
if readline fails.
Input that can’t be coerced into the specified type results in re-prompting.