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
69
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::time::Duration;
#[derive(Debug)]
#[non_exhaustive]
pub enum ErrorRoccatVulcanApi {
KeyboardNotFound,
NoLedDevice,
LedDeviceError(hidapi::HidError),
NoControlDevice,
ControlDeviceError(hidapi::HidError),
NoReadDevice,
ReadDeviceError(hidapi::HidError),
WaitedToMuchTime(Duration),
HidApiError(hidapi::HidError),
InvalidInput,
}
impl Display for ErrorRoccatVulcanApi {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::KeyboardNotFound => write!(f, "keyboard not found"),
Self::NoLedDevice => write!(f, "led device not found"),
Self::LedDeviceError(error) => write!(f, "led device error : {}", error),
Self::NoControlDevice => write!(f, "control device not found"),
Self::ControlDeviceError(error) => write!(f, "control device error : {}", error),
Self::NoReadDevice => write!(f, "read device not found"),
Self::ReadDeviceError(error) => write!(f, "read device error : {}", error),
Self::WaitedToMuchTime(duration) => write!(
f,
"waited for too long, waited for {} ms",
duration.as_secs_f64() * 1_000_f64
),
Self::HidApiError(error) => write!(f, "hid api error : {}", error),
Self::InvalidInput => write!(f, "invalide input"),
}
}
}
impl Error for ErrorRoccatVulcanApi {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::KeyboardNotFound
| Self::NoLedDevice
| Self::NoControlDevice
| Self::NoReadDevice
| Self::InvalidInput
| Self::WaitedToMuchTime(_) => None,
Self::LedDeviceError(error)
| Self::ControlDeviceError(error)
| Self::ReadDeviceError(error)
| Self::HidApiError(error) => Some(error),
}
}
}