Trait promptly::Promptable
source · [−]pub trait Promptable: Sized {
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>;
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>;
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>;
}
Expand description
A trait for convenient, opinionated prompting
Required Methods
Prompts for a value. Re-prompts on invalid and empty input.
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
Prompts for a value, returning None
for empty input. Re-prompts on invalid input.
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
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
sourceimpl Promptable for String
impl Promptable for String
sourcefn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
Prompt until you get a non-empty string
use promptly::Promptable;
String::prompt("Enter your name")?;
sourcefn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
Prompt for an optional string
use promptly::Promptable;
String::prompt_opt("Enter your phone number (optional)")?;
sourcefn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
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)
sourceimpl Promptable for char
impl Promptable for char
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for u8
impl Promptable for u8
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for u16
impl Promptable for u16
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for u32
impl Promptable for u32
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for u64
impl Promptable for u64
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for u128
impl Promptable for u128
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for usize
impl Promptable for usize
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for i8
impl Promptable for i8
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for i16
impl Promptable for i16
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for i32
impl Promptable for i32
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for i64
impl Promptable for i64
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for i128
impl Promptable for i128
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for isize
impl Promptable for isize
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for f32
impl Promptable for f32
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for f64
impl Promptable for f64
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for IpAddr
impl Promptable for IpAddr
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for Ipv4Addr
impl Promptable for Ipv4Addr
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for Ipv6Addr
impl Promptable for Ipv6Addr
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for SocketAddrV4
impl Promptable for SocketAddrV4
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for SocketAddrV6
impl Promptable for SocketAddrV6
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroI128
impl Promptable for NonZeroI128
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroI64
impl Promptable for NonZeroI64
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroI32
impl Promptable for NonZeroI32
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroI16
impl Promptable for NonZeroI16
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroI8
impl Promptable for NonZeroI8
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroIsize
impl Promptable for NonZeroIsize
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroU128
impl Promptable for NonZeroU128
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroU64
impl Promptable for NonZeroU64
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroU32
impl Promptable for NonZeroU32
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroU16
impl Promptable for NonZeroU16
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroU8
impl Promptable for NonZeroU8
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for NonZeroUsize
impl Promptable for NonZeroUsize
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
sourceimpl Promptable for PathBuf
impl Promptable for PathBuf
PathBuf prompting will use a path autocompleter
sourcefn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
Prompt until you get a non-empty path
sourcefn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
Prompt for an optional path
sourcefn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
Prompt for a path with a provided fallback value if empty
sourceimpl Promptable for bool
impl Promptable for bool
Specialized bool
prompter that supports yes/no (y/n) values
sourcefn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>
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?")?;
sourcefn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>
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?")?;
sourcefn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
fn prompt_default<S: AsRef<str>>(
msg: S,
default: Self
) -> Result<Self, ReadlineError>
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)?;