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
|
use crate::features;
use crate::{Error, Model};
mod pro;
pub use pro::Pro;
#[derive(Debug)]
pub enum Device {
Pro(Pro),
}
impl Device {
fn as_basic(&self) -> &dyn features::Basic {
match self {
Device::Pro(pro) => pro,
}
}
}
impl RawDevice for Device {
fn execute<T, U>(&self, command_id: impl Into<u8>, data: T) -> Result<U, Error>
where
T: serde::Serialize,
U: serde::de::DeserializeOwned
{
match self {
Device::Pro(pro) => pro.execute(command_id, data),
}
}
}
impl features::Basic for Device {
fn get_model(&self) -> Model {
self.as_basic().get_model()
}
fn get_status(&self) -> Result<features::Status, Error> {
self.as_basic().get_status()
}
fn get_user_retry_count(&self) -> Result<u8, Error> {
self.as_basic().get_user_retry_count()
}
fn get_admin_retry_count(&self) -> Result<u8, Error> {
self.as_basic().get_admin_retry_count()
}
}
impl From<Pro> for Device {
fn from(pro: Pro) -> Device {
Device::Pro(pro)
}
}
pub(crate) trait RawDevice {
fn execute<T, U>(&self, command_id: impl Into<u8>, data: T) -> Result<U, Error>
where
T: serde::Serialize,
U: serde::de::DeserializeOwned;
}
|