Struct question::Question [] [src]

pub struct Question<R, W> where
    R: Read,
    W: Write
{ /* fields omitted */ }

An Answer builder. Once a question has been formulated either ask or confirm may be used to get an answer.

Examples

The ask function will execute exactly the configuration of the question. This will ask the user if they would like to continue until they provide a valid yes or no response.

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .ask();

The following confirm function is exactly equivalent.

Question::new("Do you want to continue?").confirm();

Methods

impl Question<Stdin, Stdout>
[src]

[src]

Create a new Question.

Examples

Question::new("What is your favorite color?").ask();

impl<R, W> Question<R, W> where
    R: Read,
    W: Write
[src]

[src]

Add a single acceptable response to the list.

Examples

The following will ask the user if they would like to continue until either "y" or "n" is entered.

Question::new("Do you want to continue?")
    .accept("y")
    .accept("n")
    .until_acceptable()
    .ask();

[src]

Add a collection of acceptable responses to the list.

Examples

The following will ask the user if they would like to continue until either "y" or "n" is entered.

Question::new("Do you want to continue?")
    .acceptable(vec!["y", "n"])
    .until_acceptable()
    .ask();

[src]

Shorthand the most common case of a yes/no question.

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", or "no", is entered.

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .ask();

[src]

Set a maximum number of attempts to try and get an acceptable answer from the user.

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", or "no", is entered, or until they have entered 3 invalid responses.

Question::new("Do you want to continue?")
    .yes_no()
    .tries(3)
    .ask();

[src]

Never stop asking until the user provides an acceptable answer.

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", or "no", is entered.

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .ask();

[src]

Show the default response to the user that will be submitted if they enter an empty string "\n".

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", or "no", is entered. Since no default was set the prompt will be displayed with (y/n) after it, and if the user enters an empty string no answer will be returned and they will be re-prompted.

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .show_defaults()
    .ask();

If either Answer::YES or Answer::NO have been set as default then the prompt will be shown with that entry capitalized, either (Y/n) or (y/N).

[src]

Provide a default answer.

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", "no", or "" an empty string is entered. If an empty string is entered Answer::YES will be returned.

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .default(Answer::YES)
    .show_defaults()
    .ask();

[src]

Provide a clarification to be shown if the user does not enter an acceptable answer on the first try.

Examples

The following will ask the user if they would like to continue until either "y", "n", "yes", "no", or "" an empty string is entered. If an empty string is entered Answer::YES will be returned. If the user does not enter a valid response on the first attempt, the clarification will be added to the prompt.

Please enter either 'yes' or 'no' Do you want to continue? (Y/n)

Question::new("Do you want to continue?")
    .yes_no()
    .until_acceptable()
    .default(Answer::YES)
    .show_defaults()
    .clarification("Please enter either 'yes' or 'no'\n")
    .ask();

[src]

Ask the user a question exactly as it has been built.

Examples

The following will return whatever the user enters as an Answer::RESPONSE(String).

Question::new("What is your favorite color?").ask();

[src]

Ask a user a yes/no question until an acceptable response is given.

Examples

Question::new("Continue?").confirm();

Trait Implementations

impl<R: Clone, W: Clone> Clone for Question<R, W> where
    R: Read,
    W: Write
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<R, W> Send for Question<R, W> where
    R: Send,
    W: Send

impl<R, W> Sync for Question<R, W> where
    R: Sync,
    W: Sync