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

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

Prompts for a value, returning None for empty input. Re-prompts on invalid input.

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]

[src]

Prompt until you get a non-empty string

use promptly::Promptable;
String::prompt("Enter your name");

[src]

Prompt for an optional string

use promptly::Promptable;
String::prompt_opt("Enter your phone number (optional)");

[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

[src]

Prompt until you get a non-empty path

[src]

Prompt for an optional path

[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

[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?");

[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?");

[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);

impl<P: Promptable> Promptable for Option<P>
[src]

[src]

[src]

[src]

Implementors