#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Key {
Enter,
Space,
Backspace,
Escape,
Tab,
Up,
Down,
Left,
Right,
Home,
End,
Char(char),
Interrupt,
Unknown,
}
impl Key {
#[must_use]
pub const fn is_interrupt(self) -> bool {
matches!(self, Self::Interrupt)
}
}
#[cfg(test)]
mod tests {
use super::Key;
#[test]
fn only_interrupt_reports_as_interrupt() {
assert!(Key::Interrupt.is_interrupt());
for key in [
Key::Enter,
Key::Escape,
Key::Char('a'),
Key::Space,
Key::Unknown,
] {
assert!(!key.is_interrupt());
}
}
}