Trait promptly::Promptable
[−]
[src]
pub trait Promptable: Sized { fn prompt<S: AsRef<str>>(msg: S) -> Self; fn prompt_opt<S: AsRef<str>>(msg: S) -> Option<Self>; fn prompt_default<S: AsRef<str>>(msg: S, default: Self) -> Self; }
A trait for convenient, opinionated prompting
Required Methods
fn prompt<S: AsRef<str>>(msg: S) -> Self
Prompts for a value. Re-prompts on invalid and empty input.
fn prompt_opt<S: AsRef<str>>(msg: S) -> Option<Self>
Prompts for a value, returning None
for empty input. Re-prompts on invalid input.
fn prompt_default<S: AsRef<str>>(msg: S, default: Self) -> Self
Prompts for a value with a default value for empty input. Re-prompts on invalid input.
The default value will be mentioned in the prompt message
Implementations on Foreign Types
impl Promptable for String
[src]
fn prompt<S: AsRef<str>>(msg: S) -> Self
[src]
Prompt until you get a non-empty string
use promptly::Promptable; String::prompt("Enter your name");
fn prompt_opt<S: AsRef<str>>(msg: S) -> Option<Self>
[src]
Prompt for an optional string
use promptly::Promptable; String::prompt_opt("Enter your phone number (optional)");
fn prompt_default<S: AsRef<str>>(msg: S, default: Self) -> Self
[src]
Prompt for a string with a provided fallback value if empty.
use promptly::Promptable; String::prompt_default("Enter your country", "USA".into());
Default value is visible in the prompt as: (default=USA)
impl Promptable for PathBuf
[src]
PathBuf prompting will use a path autocompleter
impl Promptable for bool
[src]
Specialized bool
prompter that supports yes/no (y/n) values
fn prompt<S: AsRef<str>>(msg: S) -> Self
[src]
Prompt for bool
represented as true/false
, yes/no
, or y/n
input
The prompt will display the options: (y/n)
use promptly::Promptable; bool::prompt("Do you accept the terms?");
fn prompt_opt<S: AsRef<str>>(msg: S) -> Option<Self>
[src]
Prompt for optional bool
input. Empty input returns None
.
The prompt will display the options: (y/n)
use promptly::Promptable; bool::prompt_opt("Did you even read this question?");
fn prompt_default<S: AsRef<str>>(msg: S, default: Self) -> Self
[src]
Prompt for optional bool
input. Empty input returns None
.
The prompt will also display the options: (Y/n)
or (y/N)
depending on the default
use promptly::Promptable; bool::prompt_default("Would you like to send us money?", true);