Struct QuestionOption

Source
pub struct QuestionOption { /* private fields */ }

Implementations§

Source§

impl QuestionOption

Source

pub fn new(name: String) -> QuestionOption

Examples found in repository?
examples/multiple_choice_food_menu.rs (line 25)
6fn main() {
7    // let mut ask = ask::Ask::new();
8    // ask.question(OpenEnded::new( "question?".to_string()));
9    // ask.all();
10
11    // let mut open_ended = OpenEnded::new("question?".to_string());
12    // let answers = open_ended.send();
13
14    let mut multiple_choice = MultipleChoice::new("What would you like to order?".to_owned());
15
16    let answer_collections = multiple_choice
17        .add_option_group(
18            OptionGroup::new("Entrees")
19                .add_option_by_str("Calamari".to_owned())
20                .add_option_by_str("Buffalo wings".to_owned())
21                .add_option_by_str("Shrimp".to_owned())
22        )
23        .add_option_group(
24            OptionGroup::new("Main Course")
25                .add_option(QuestionOption::new("Lobster".to_owned()))
26                .add_option(QuestionOption::new("T-Bone".to_owned()).toggle_selected(None))//toggle the selected to opposite to what it currently is
27                .add_option(QuestionOption::new("Burger".to_owned()).toggle_selected(Some(false)))
28                .add_option(QuestionOption::new("Duck".to_owned()).toggle_selected(Some(true))) //set this option to be selected by default asking the question
29        )
30        .set_validation(Box::new(|answer_collection| {
31                validate::group_options::selections_are_gtoe(& answer_collection, 0) &&
32                validate::group_options::selections_are_ltoe(& answer_collection, 3)
33            })
34        )
35        // .replace_continue_btn("CAN CONTINUE!!".to_owned(), "CANNOT CONTINUE!!".to_owned()) //can customize continue btn
36        .send()
37        .unwrap();
38
39
40    println!("");
41
42    // let answer_collections = multiple_choice.to_answer_collections(); //can pull the answer_collections at any time
43    for answer_sets in answer_collections.answer_sets{
44        for answer in answer_sets.answers{
45            println!("{}", answer);
46        }
47    }
48}
Source

pub fn toggle_selected(self, switch: Option<bool>) -> Self

Examples found in repository?
examples/multiple_choice_food_menu.rs (line 26)
6fn main() {
7    // let mut ask = ask::Ask::new();
8    // ask.question(OpenEnded::new( "question?".to_string()));
9    // ask.all();
10
11    // let mut open_ended = OpenEnded::new("question?".to_string());
12    // let answers = open_ended.send();
13
14    let mut multiple_choice = MultipleChoice::new("What would you like to order?".to_owned());
15
16    let answer_collections = multiple_choice
17        .add_option_group(
18            OptionGroup::new("Entrees")
19                .add_option_by_str("Calamari".to_owned())
20                .add_option_by_str("Buffalo wings".to_owned())
21                .add_option_by_str("Shrimp".to_owned())
22        )
23        .add_option_group(
24            OptionGroup::new("Main Course")
25                .add_option(QuestionOption::new("Lobster".to_owned()))
26                .add_option(QuestionOption::new("T-Bone".to_owned()).toggle_selected(None))//toggle the selected to opposite to what it currently is
27                .add_option(QuestionOption::new("Burger".to_owned()).toggle_selected(Some(false)))
28                .add_option(QuestionOption::new("Duck".to_owned()).toggle_selected(Some(true))) //set this option to be selected by default asking the question
29        )
30        .set_validation(Box::new(|answer_collection| {
31                validate::group_options::selections_are_gtoe(& answer_collection, 0) &&
32                validate::group_options::selections_are_ltoe(& answer_collection, 3)
33            })
34        )
35        // .replace_continue_btn("CAN CONTINUE!!".to_owned(), "CANNOT CONTINUE!!".to_owned()) //can customize continue btn
36        .send()
37        .unwrap();
38
39
40    println!("");
41
42    // let answer_collections = multiple_choice.to_answer_collections(); //can pull the answer_collections at any time
43    for answer_sets in answer_collections.answer_sets{
44        for answer in answer_sets.answers{
45            println!("{}", answer);
46        }
47    }
48}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.