use crate::Result;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum StorageType {
SSD,
HDD,
NVMe,
EMmc,
SD,
USB,
Unknown,
}
impl std::fmt::Display for StorageType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StorageType::SSD => write!(f, "SSD"),
StorageType::HDD => write!(f, "HDD"),
StorageType::NVMe => write!(f, "NVMe"),
StorageType::EMmc => write!(f, "eMMC"),
StorageType::SD => write!(f, "SD Card"),
StorageType::USB => write!(f, "USB"),
StorageType::Unknown => write!(f, "Unknown"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageInfo {
pub model: String,
pub storage_type: StorageType,
pub capacity_gb: f64,
pub available_gb: f64,
pub used_gb: f64,
pub mount_point: String,
pub file_system: Option<String>,
pub removable: bool,
pub read_speed_mb_s: Option<f32>,
pub write_speed_mb_s: Option<f32>,
}
impl StorageInfo {
pub fn query_all() -> Result<Vec<Self>> {
let storage_devices = vec![Self {
model: "System Disk".to_string(),
storage_type: StorageType::SSD,
capacity_gb: 256.0,
available_gb: 128.0,
used_gb: 128.0,
mount_point: "C:".to_string(),
file_system: Some("NTFS".to_string()),
removable: false,
read_speed_mb_s: None,
write_speed_mb_s: None,
}];
Ok(storage_devices)
}
pub fn model(&self) -> &str {
&self.model
}
pub fn drive_type(&self) -> &StorageType {
&self.storage_type
}
pub fn capacity_gb(&self) -> f64 {
self.capacity_gb
}
pub fn available_gb(&self) -> f64 {
self.available_gb
}
pub fn used_gb(&self) -> f64 {
self.used_gb
}
pub fn usage_percent(&self) -> f64 {
if self.capacity_gb > 0.0 {
(self.used_gb / self.capacity_gb) * 100.0
} else {
0.0
}
}
pub fn has_free_space(&self, required_gb: f64) -> bool {
self.available_gb >= required_gb
}
}