1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::fmt;
#[derive(Clone, Debug, PartialEq)]
pub struct OptionAnswer {
pub index: usize,
pub value: String,
}
impl OptionAnswer {
pub fn new(index: usize, value: &str) -> Self {
Self {
index,
value: value.to_string(),
}
}
#[allow(unused)]
pub(in crate) fn from_str_list(vals: &[&str]) -> Vec<OptionAnswer> {
vals.iter()
.enumerate()
.map(|(index, value)| Self {
index,
value: value.to_string(),
})
.collect()
}
#[allow(unused)]
pub(in crate) fn from_idx_str_list(vals: &[(usize, &str)]) -> Vec<OptionAnswer> {
vals.iter()
.map(|(index, value)| Self {
index: *index,
value: value.to_string(),
})
.collect()
}
}
impl fmt::Display for OptionAnswer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value)
}
}