Skip to main content

pacenotes_installer\choices/
choice_list.rs

1/// One row of a list.
2#[derive(Clone, Debug, PartialEq, Eq)]
3pub struct ChoiceOption {
4    /// `game/directory/name`, the key the cache and the ledger use.
5    pub key: String,
6    /// The path below the category, e.g. `polish / male / Kamil`.
7    pub label: String,
8}
9
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct ChoiceList {
12    /// The schema's category id, e.g. `pacenotes_shared::CATEGORY_CODRIVER`.
13    pub category: &'static str,
14    pub options: Vec<ChoiceOption>,
15    pub selected: Option<usize>,
16}
17
18impl ChoiceList {
19    pub fn selected_key(&self) -> Option<&str> {
20        self.selected.map(|index| self.options[index].key.as_str())
21    }
22
23    /// An empty list asks nothing, as a category the server does not offer must not block Install.
24    pub fn is_satisfied(&self) -> bool {
25        self.options.is_empty() || self.selected.is_some()
26    }
27}