selectable.rs

 1/// A trait for elements that can be selected.
 2pub trait Selectable {
 3    /// Sets whether the element is selected.
 4    fn selected(self, selected: bool) -> Self;
 5}
 6
 7#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
 8pub enum Selection {
 9    #[default]
10    Unselected,
11    Indeterminate,
12    Selected,
13}
14
15impl Selection {
16    pub fn inverse(&self) -> Self {
17        match self {
18            Self::Unselected | Self::Indeterminate => Self::Selected,
19            Self::Selected => Self::Unselected,
20        }
21    }
22}