[][src]Struct cowmug::Question

pub struct Question { /* fields omitted */ }

pub struct QuestionList

A Struct to wrapper questions and send it to Prompt to ask it

Examples

let mut question = Question::new(String::from("choose a color: ");
question.add_choice(String::from("Red"));
question.add_choice(String::from("Blue"));
question.add_choice(String::from("Green"));

Implementations

impl Question[src]

pub fn new(question: String) -> Self[src]

pub fn question(&self) -> &String[src]

Return the question of this instance

Examples

let mut question = Question::new(String::from("choose a color: ");
println!("{}", question.question());

pub fn answer_mut(&mut self) -> &mut Option<Answer>[src]

!WARNING This method is used only on prompt::Prompt Because only prompt::Prompt must use it the return Answer is private

pub fn index_answer(&self) -> Option<usize>[src]

Return the index of choices

Examples

let mut list_questions: Vec<Question> = Vec::new();
let mut question = Question::new(String::from("choose a color: ");
question.add_choice(String::from("Red"));
question.add_choice(String::from("Blue"));
question.add_choice(String::from("Green"));
list_questions.push(question);
prompt.exec(&mut list_questions).unwrap();
let index_answer = list_questions.get(0).unwrap().question.index_answer().unwrap();
println!("Index chosen by the user: {}", index_answer);

pub fn string_answer(&self) -> Option<&String>[src]

Return the string of the chosen choice.

Examples

let mut list_questions: Vec<Question> = Vec::new();
let mut question = Question::new(String::from("choose a color: ");
question.add_choice(String::from("Red"));
question.add_choice(String::from("Blue"));
question.add_choice(String::from("Green"));
list_questions.push(question);
prompt.exec(&mut list_questions).unwrap();
let string_answer = list_questions.get(0).unwrap().question.string_answer().unwrap();
println!("choice from user: {}", string_answer);

pub fn add_choice(&mut self, choice: String)[src]

Add a choice to this question

Examples

let mut question = Question::new(String::from("choose a color: ");
question.add_choice(String::from("Red"));
question.add_choice(String::from("Blue"));
question.add_choice(String::from("Green"));

pub fn add_choices(&mut self, choices: Vec<String>)[src]

Add N choices to this question

Examples

let mut question = Question::new(String::from("choose a color: ");
   let choices: Vec<String> = vec![
String::from("Red"),
String::from("Blue"),
String::from("Green"),
];
question.add_choices(choices);

pub fn choices(&self) -> &Vec<String>[src]

Return a reference to vec choices of this question

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.