1use crate::Result;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct USBDevice {
7 pub vendor_id: String,
9 pub product_id: String,
11 pub vendor_name: String,
13 pub product_name: String,
15 pub device_class: String,
17 pub usb_version: String,
19 pub serial_number: Option<String>,
21 pub bus_number: u8,
23 pub device_address: u8,
25 pub port_path: Option<String>,
27 pub driver: Option<String>,
29 pub connected: bool,
31}
32
33impl USBDevice {
34 pub fn query_all() -> Result<Vec<Self>> {
36 Ok(vec![])
39 }
40
41 pub fn vendor_id(&self) -> &str {
43 &self.vendor_id
44 }
45
46 pub fn product_id(&self) -> &str {
48 &self.product_id
49 }
50
51 pub fn vendor_name(&self) -> &str {
53 &self.vendor_name
54 }
55
56 pub fn product_name(&self) -> &str {
58 &self.product_name
59 }
60
61 pub fn device_class(&self) -> &str {
63 &self.device_class
64 }
65
66 pub fn usb_version(&self) -> &str {
68 &self.usb_version
69 }
70
71 pub fn is_connected(&self) -> bool {
73 self.connected
74 }
75
76 pub fn is_storage_device(&self) -> bool {
78 self.device_class.to_lowercase().contains("mass storage")
79 || self.device_class.to_lowercase().contains("storage")
80 }
81
82 pub fn is_input_device(&self) -> bool {
84 self.device_class.to_lowercase().contains("hid")
85 || self.device_class.to_lowercase().contains("human interface")
86 || self.device_class.to_lowercase().contains("input")
87 }
88
89 pub fn is_audio_device(&self) -> bool {
91 self.device_class.to_lowercase().contains("audio")
92 }
93
94 pub fn is_video_device(&self) -> bool {
96 self.device_class.to_lowercase().contains("video")
97 || self.device_class.to_lowercase().contains("camera")
98 }
99
100 pub fn is_high_speed(&self) -> bool {
102 self.usb_version.contains("3.")
103 || self.usb_version.contains("3")
104 && !self.usb_version.contains("2.")
105 && !self.usb_version.contains("1.")
106 }
107}