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]
impl<R, W> Question<R, W> where
R: Read,
W: Write,
[src]
R: Read,
W: Write,
pub fn accept(&mut self, accepted: &str) -> &mut Question<R, W>
[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();
pub fn acceptable(&mut self, accepted: Vec<&str>) -> &mut Question<R, W>
[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();
pub fn yes_no(&mut self) -> &mut Question<R, W>
[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();
pub fn tries(&mut self, tries: u64) -> &mut Question<R, W>
[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();
pub fn until_acceptable(&mut self) -> &mut Question<R, W>
[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();
pub fn show_defaults(&mut self) -> &mut Question<R, W>
[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)
.
pub fn default(&mut self, answer: Answer) -> &mut Question<R, W>
[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();
pub fn clarification(&mut self, c: &str) -> &mut Question<R, W>
[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();
pub fn ask(&mut self) -> Option<Answer>
[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();
pub fn confirm(&mut self) -> Answer
[src]
Ask a user a yes/no question until an acceptable response is given.
Examples
Question::new("Continue?").confirm();