[][src]Trait promptly::Promptable

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>; }

A trait for convenient, opinionated prompting

Required methods

fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>

Prompts for a value. Re-prompts on invalid and empty input.

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>

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

Loading content...

Implementations on Foreign Types

impl Promptable for String[src]

fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>[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) -> Result<Option<Self>, ReadlineError>[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
) -> Result<Self, ReadlineError>
[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 char[src]

impl Promptable for u8[src]

impl Promptable for u16[src]

impl Promptable for u32[src]

impl Promptable for u64[src]

impl Promptable for u128[src]

impl Promptable for usize[src]

impl Promptable for i8[src]

impl Promptable for i16[src]

impl Promptable for i32[src]

impl Promptable for i64[src]

impl Promptable for i128[src]

impl Promptable for isize[src]

impl Promptable for f32[src]

impl Promptable for f64[src]

impl Promptable for IpAddr[src]

impl Promptable for Ipv4Addr[src]

impl Promptable for Ipv6Addr[src]

impl Promptable for SocketAddrV4[src]

impl Promptable for SocketAddrV6[src]

impl Promptable for NonZeroI128[src]

impl Promptable for NonZeroI64[src]

impl Promptable for NonZeroI32[src]

impl Promptable for NonZeroI16[src]

impl Promptable for NonZeroI8[src]

impl Promptable for NonZeroIsize[src]

impl Promptable for NonZeroU128[src]

impl Promptable for NonZeroU64[src]

impl Promptable for NonZeroU32[src]

impl Promptable for NonZeroU16[src]

impl Promptable for NonZeroU8[src]

impl Promptable for NonZeroUsize[src]

impl Promptable for PathBuf[src]

PathBuf prompting will use a path autocompleter

fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>[src]

Prompt until you get a non-empty path

fn prompt_opt<S: AsRef<str>>(msg: S) -> Result<Option<Self>, ReadlineError>[src]

Prompt for an optional path

fn prompt_default<S: AsRef<str>>(
    msg: S,
    default: Self
) -> Result<Self, ReadlineError>
[src]

Prompt for a path with a provided fallback value if empty

impl Promptable for bool[src]

Specialized bool prompter that supports yes/no (y/n) values

fn prompt<S: AsRef<str>>(msg: S) -> Result<Self, ReadlineError>[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) -> Result<Option<Self>, ReadlineError>[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
) -> Result<Self, ReadlineError>
[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)?;
Loading content...

Implementors

Loading content...