Skip to main content

windows_erg/system/
types.rs

1//! Types for host system inventory.
2
3use std::borrow::Cow;
4
5/// Strongly-typed machine GUID value.
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
7pub struct MachineGuid(String);
8
9impl MachineGuid {
10    /// Create a new machine GUID wrapper.
11    pub fn new(value: String) -> Self {
12        Self(value)
13    }
14
15    /// Return GUID as string slice.
16    pub fn as_str(&self) -> &str {
17        &self.0
18    }
19
20    /// Consume into owned string.
21    pub fn into_inner(self) -> String {
22        self.0
23    }
24}
25
26/// Snapshot section identifier used for partial-result reporting.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28pub enum SnapshotSection {
29    /// Host identity details (hostname).
30    Identity,
31    /// Operating system details.
32    Os,
33    /// GUID values (machine/firmware).
34    Guids,
35    /// BIOS details.
36    Bios,
37    /// Logical volumes.
38    LogicalDisks,
39    /// Physical disks.
40    PhysicalDisks,
41    /// Network interfaces.
42    Network,
43    /// User/account inventory.
44    Users,
45}
46
47/// Section-level error recorded during snapshot collection.
48#[derive(Debug, Clone)]
49pub struct SnapshotSectionError {
50    /// Section that failed.
51    pub section: SnapshotSection,
52    /// Human-readable failure message.
53    pub message: Cow<'static, str>,
54}
55
56/// Top-level host inventory snapshot.
57#[derive(Debug, Clone)]
58pub struct HostSnapshot {
59    /// Host identity details.
60    pub identity: HostIdentity,
61    /// Operating system details.
62    pub os: OsInfo,
63    /// GUID values.
64    pub guids: GuidInfo,
65    /// BIOS/firmware details when available.
66    pub bios: Option<BiosInfo>,
67    /// Logical volume inventory.
68    pub logical_disks: Vec<LogicalDiskInfo>,
69    /// Physical disk inventory.
70    pub physical_disks: Vec<PhysicalDiskInfo>,
71    /// Network interface inventory.
72    pub networks: Vec<NetworkInterfaceInfo>,
73    /// User/account inventory.
74    pub users: Vec<UserInfo>,
75    /// Per-section failures captured while building this snapshot.
76    pub section_errors: Vec<SnapshotSectionError>,
77}
78
79/// Host identity data.
80#[derive(Debug, Clone)]
81pub struct HostIdentity {
82    /// NetBIOS/DNS hostname.
83    pub hostname: String,
84}
85
86/// OS details.
87#[derive(Debug, Clone)]
88pub struct OsInfo {
89    /// Marketing name when available (for example: Windows 11 Pro).
90    pub product_name: Option<String>,
91    /// Semantic label derived from major/minor/build mapping.
92    pub release_label: Option<String>,
93    /// Build number.
94    pub build_number: u32,
95    /// Major version.
96    pub major_version: u32,
97    /// Minor version.
98    pub minor_version: u32,
99}
100
101/// GUID values discovered from host sources.
102#[derive(Debug, Clone)]
103pub struct GuidInfo {
104    /// Registry machine GUID.
105    pub machine_guid: Option<MachineGuid>,
106    /// Firmware/system UUID when available from SMBIOS.
107    pub firmware_guid: Option<String>,
108}
109
110/// BIOS summary information.
111#[derive(Debug, Clone)]
112pub struct BiosInfo {
113    /// BIOS vendor.
114    pub vendor: Option<String>,
115    /// BIOS version string.
116    pub version: Option<String>,
117    /// BIOS release date string.
118    pub release_date: Option<String>,
119    /// System manufacturer from firmware descriptors.
120    pub system_manufacturer: Option<String>,
121    /// System product name from firmware descriptors.
122    pub system_product_name: Option<String>,
123}
124
125/// Logical disk information.
126#[derive(Debug, Clone)]
127pub struct LogicalDiskInfo {
128    /// Drive root path (for example: C:\\).
129    pub root: String,
130    /// Volume label when available.
131    pub volume_label: Option<String>,
132    /// File system type when available.
133    pub file_system: Option<String>,
134    /// Total size in bytes.
135    pub total_bytes: u64,
136    /// Free bytes available to caller.
137    pub free_bytes_available: u64,
138    /// Total free bytes on volume.
139    pub total_free_bytes: u64,
140}
141
142/// Physical disk information.
143#[derive(Debug, Clone)]
144pub struct PhysicalDiskInfo {
145    /// Physical disk path (for example: \\.\\PhysicalDrive0).
146    pub path: String,
147    /// Disk size in bytes when available.
148    pub size_bytes: u64,
149}
150
151/// Network interface information.
152#[derive(Debug, Clone)]
153pub struct NetworkInterfaceInfo {
154    /// Interface display name.
155    pub name: String,
156    /// MAC address in canonical form when available.
157    pub mac_address: Option<String>,
158    /// IPv4/IPv6 addresses.
159    pub addresses: Vec<String>,
160}
161
162/// User/account information.
163#[derive(Debug, Clone)]
164pub struct UserInfo {
165    /// Username.
166    pub username: String,
167    /// Optional SID string.
168    pub sid: Option<String>,
169    /// Data source label (for example: profile_list/current_user).
170    pub source: &'static str,
171}