summaryrefslogtreecommitdiff
path: root/src/devices.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices.rs')
-rw-r--r--src/devices.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/devices.rs b/src/devices.rs
new file mode 100644
index 0000000..a40207b
--- /dev/null
+++ b/src/devices.rs
@@ -0,0 +1,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;
+}