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