disk_serial_number/
lib.rs1#[derive(Debug, Clone)]
2pub struct DiskInfo {
3 pub name: String,
4 pub model: Option<String>,
5 pub serial_number: Option<String>,
6 pub removable: Option<bool>,
7}
8
9#[cfg(windows)]
10use wmi::WMIError;
11
12#[derive(Debug, thiserror::Error)]
13pub enum ProviderError {
14 #[error("Failed to execute external command: {0}")]
15 CommandFailed(#[from] std::io::Error),
16 #[error("Command returned non-zero status: {0}")]
17 CommandUnsuccessful(String),
18 #[error("Failed to parse output: {0}")]
19 ParsingFailed(String),
20 #[error("JSON processing failed: {0}")]
21 JsonError(#[from] serde_json::Error),
22 #[error("Specified device not found")]
23 DeviceNotFound,
24
25 #[cfg(windows)]
26 #[error("WMI operation failed: {0}")]
27 WmiError(#[from] WMIError),
28}
29
30pub trait DiskInfoProvider {
31 fn get_all_disks() -> Result<Vec<DiskInfo>, ProviderError>;
32}
33
34cfg_if::cfg_if! {
35 if #[cfg(target_os = "linux")] {
36 mod linux;
37 use linux::LinuxProvider as PlatformProvider;
38 } else if #[cfg(target_os = "windows")] {
39 mod windows;
40 use windows::WindowsProvider as PlatformProvider;
41 } else if #[cfg(target_os = "macos")] {
42 mod macos;
43 use macos::MacosProvider as PlatformProvider;
44 } else {
45 compile_error!("Unsupported OS");
46 }
47}
48
49pub fn get_all_disks() -> Result<Vec<DiskInfo>, ProviderError> {
50 PlatformProvider::get_all_disks()
51}