[−][src]Struct cowmug::Prompt
Struct that take control of stdout and ask questions
Implementations
impl Prompt
[src]
pub fn new() -> Self
[src]
pub fn exec(&mut self, questions: &mut Vec<Question>) -> Result<(), Error>
[src]
Given a vector of Question, exec will iter through it and ask all questions and store the answer on it's on question
Examples
let mut list_questions: Vec<Question> = Vec::new(); let mut pizza_size = Question::new(String::from("Choose the size of your pizza: ")); pizza_size.add_choice(String::from("Large")); pizza_size.add_choice(String::from("Medium")); pizza_size.add_choice(String::from("Small")); list_questions.push(pizza_size); let mut pizza_flavor = Question::new(String::from("Choose pizza:")); let pizza_flavor_choices: Vec<String> = vec![ String::from("peperoni"), String::from("4 cheese"), String::from("chicken"), ]; pizza_flavor.add_choices(pizza_flavor_choices); list_questions.push(pizza_flavor); let mut prompt = Prompt::new(); prompt.exec(&mut list_questions).unwrap(); let answer_size = list_questions.get(0).unwrap().string_answer().unwrap(); let answer_flavor = list_questions.get(1).unwrap().string_answer().unwrap(); let mut choices_is_correct = Question::new(format!( "You choose pizza {} with {}, you confirm?", answer_size, answer_flavor )); choices_is_correct.add_choice(String::from("yes")); choices_is_correct.add_choice(String::from("no")); list_questions.clear(); list_questions.push(choices_is_correct); prompt.exec(&mut list_questions).unwrap(); if let Some(is_correct) = list_questions.get(0).unwrap().string_answer() { if is_correct.as_str() == "yes" { println!("Great! See ya"); } else { println!("Thats is terrible!! =/ "); } }
Auto Trait Implementations
impl RefUnwindSafe for Prompt
impl Send for Prompt
impl Sync for Prompt
impl Unpin for Prompt
impl UnwindSafe for Prompt
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,