hardware_query/
storage.rs1use crate::Result;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub enum StorageType {
7 SSD,
8 HDD,
9 NVMe,
10 EMmc,
11 SD,
12 USB,
13 Unknown,
14}
15
16impl std::fmt::Display for StorageType {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 StorageType::SSD => write!(f, "SSD"),
20 StorageType::HDD => write!(f, "HDD"),
21 StorageType::NVMe => write!(f, "NVMe"),
22 StorageType::EMmc => write!(f, "eMMC"),
23 StorageType::SD => write!(f, "SD Card"),
24 StorageType::USB => write!(f, "USB"),
25 StorageType::Unknown => write!(f, "Unknown"),
26 }
27 }
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct StorageInfo {
33 pub model: String,
35 pub storage_type: StorageType,
37 pub capacity_gb: f64,
39 pub available_gb: f64,
41 pub used_gb: f64,
43 pub mount_point: String,
45 pub file_system: Option<String>,
47 pub removable: bool,
49 pub read_speed_mb_s: Option<f32>,
51 pub write_speed_mb_s: Option<f32>,
53}
54
55impl StorageInfo {
56 pub fn query_all() -> Result<Vec<Self>> {
58 let storage_devices = vec![Self {
61 model: "System Disk".to_string(),
62 storage_type: StorageType::SSD,
63 capacity_gb: 256.0,
64 available_gb: 128.0,
65 used_gb: 128.0,
66 mount_point: "C:".to_string(),
67 file_system: Some("NTFS".to_string()),
68 removable: false,
69 read_speed_mb_s: None,
70 write_speed_mb_s: None,
71 }];
72
73 Ok(storage_devices)
74 }
75
76 pub fn model(&self) -> &str {
78 &self.model
79 }
80
81 pub fn drive_type(&self) -> &StorageType {
83 &self.storage_type
84 }
85
86 pub fn capacity_gb(&self) -> f64 {
88 self.capacity_gb
89 }
90
91 pub fn available_gb(&self) -> f64 {
93 self.available_gb
94 }
95
96 pub fn used_gb(&self) -> f64 {
98 self.used_gb
99 }
100
101 pub fn usage_percent(&self) -> f64 {
103 if self.capacity_gb > 0.0 {
104 (self.used_gb / self.capacity_gb) * 100.0
105 } else {
106 0.0
107 }
108 }
109
110 pub fn has_free_space(&self, required_gb: f64) -> bool {
112 self.available_gb >= required_gb
113 }
114}