win_hotkey/
error.rs

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
use crate::keys::VirtualKey;
use std::error::Error;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;

#[derive(Debug)]
pub enum HotkeyError {
    InvalidKey(String),
    InvalidKeyChar(char),
    NotAModkey(VirtualKey),
    RegistrationFailed,
    UnregistrationFailed,
}

impl Display for HotkeyError {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        match *self {
            HotkeyError::InvalidKey(ref key) => write!(f, "invalid key name `{}`", key),
            HotkeyError::InvalidKeyChar(ref ch) => write!(f, "invalid key char `{}`", ch),
            HotkeyError::NotAModkey(ref vkey) => write!(f, "VKey is not a ModKey {:?}", vkey),
            HotkeyError::RegistrationFailed => write!(
                f,
                "Hotkey registration failed. Hotkey or Id might be in use already"
            ),
            HotkeyError::UnregistrationFailed => write!(f, "Hotkey unregistration failed"),
        }
    }
}

impl Error for HotkeyError {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        None
    }
}