Skip to content

Commit 1b25168

Browse files
fix: apply cargo fmt formatting
1 parent ce4a7ac commit 1b25168

5 files changed

Lines changed: 56 additions & 72 deletions

File tree

src/adapters/secondary/system/linux.rs

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,12 @@ limitations under the License.
3434
//! 3. Fallback: sysinfo crate (cross-platform)
3535
3636
use crate::domain::{
37-
combine_cpu_info,
38-
determine_memory_speed,
39-
determine_memory_type,
40-
parse_dmidecode_bios_info,
41-
parse_dmidecode_chassis_info,
42-
parse_dmidecode_cpu,
43-
parse_dmidecode_memory,
44-
parse_dmidecode_system_info,
45-
parse_free_output,
46-
parse_hostname_output,
47-
parse_ip_output,
48-
parse_lscpu_output,
49-
BiosInfo,
50-
ChassisInfo,
51-
CpuInfo,
52-
GpuDevice,
53-
GpuInfo,
54-
GpuVendor,
55-
MemoryInfo,
56-
MotherboardInfo,
57-
NetworkInfo,
58-
NetworkInterface,
59-
NetworkInterfaceType,
60-
NumaNode,
61-
StorageDevice,
62-
StorageInfo,
63-
StorageType,
64-
SystemError,
65-
SystemInfo,
37+
combine_cpu_info, determine_memory_speed, determine_memory_type, parse_dmidecode_bios_info,
38+
parse_dmidecode_chassis_info, parse_dmidecode_cpu, parse_dmidecode_memory,
39+
parse_dmidecode_system_info, parse_free_output, parse_hostname_output, parse_ip_output,
40+
parse_lscpu_output, BiosInfo, ChassisInfo, CpuInfo, GpuDevice, GpuInfo, GpuVendor, MemoryInfo,
41+
MotherboardInfo, NetworkInfo, NetworkInterface, NetworkInterfaceType, NumaNode, StorageDevice,
42+
StorageInfo, StorageType, SystemError, SystemInfo,
6643
};
6744

6845
use crate::domain::parsers::storage::{
@@ -156,7 +133,11 @@ impl LinuxSystemInfoProvider {
156133
// Skip tiny devices (< 1GB)
157134
const MIN_SIZE: u64 = 1_000_000_000;
158135
if size_bytes < MIN_SIZE {
159-
log::trace!("Skipping small device {}: {} bytes", device_name, size_bytes);
136+
log::trace!(
137+
"Skipping small device {}: {} bytes",
138+
device_name,
139+
size_bytes
140+
);
160141
continue;
161142
}
162143

@@ -273,13 +254,15 @@ impl LinuxSystemInfoProvider {
273254
])
274255
.timeout(Duration::from_secs(10));
275256

276-
let output = self.command_executor.execute(&cmd).await.map_err(|e| {
277-
SystemError::CommandFailed {
278-
command: "lsblk".to_string(),
279-
exit_code: None,
280-
stderr: e.to_string(),
281-
}
282-
})?;
257+
let output =
258+
self.command_executor
259+
.execute(&cmd)
260+
.await
261+
.map_err(|e| SystemError::CommandFailed {
262+
command: "lsblk".to_string(),
263+
exit_code: None,
264+
stderr: e.to_string(),
265+
})?;
283266

284267
if !output.success {
285268
return Err(SystemError::CommandFailed {
@@ -331,8 +314,12 @@ impl LinuxSystemInfoProvider {
331314
for sec_device in secondary {
332315
if let Some(pri_device) = primary.iter_mut().find(|d| d.name == sec_device.name) {
333316
// Fill in missing fields from secondary
334-
pri_device.serial_number = pri_device.serial_number.take().or(sec_device.serial_number);
335-
pri_device.firmware_version = pri_device.firmware_version.take().or(sec_device.firmware_version);
317+
pri_device.serial_number =
318+
pri_device.serial_number.take().or(sec_device.serial_number);
319+
pri_device.firmware_version = pri_device
320+
.firmware_version
321+
.take()
322+
.or(sec_device.firmware_version);
336323
pri_device.wwn = pri_device.wwn.take().or(sec_device.wwn);
337324

338325
if pri_device.model.is_empty() && !sec_device.model.is_empty() {
@@ -400,8 +387,9 @@ impl LinuxSystemInfoProvider {
400387
iface.driver = Some(driver_str.clone());
401388

402389
// Driver version
403-
let version_path =
404-
PathBuf::from("/sys/module").join(&driver_str).join("version");
390+
let version_path = PathBuf::from("/sys/module")
391+
.join(&driver_str)
392+
.join("version");
405393
if let Ok(version) = self.read_sysfs_file(&version_path) {
406394
iface.driver_version = Some(version.trim().to_string());
407395
}
@@ -527,7 +515,10 @@ impl SystemInfoProvider for LinuxSystemInfoProvider {
527515

528516
// Enrich with lsblk
529517
if let Ok(lsblk_devices) = self.detect_storage_lsblk().await {
530-
log::debug!("lsblk found {} devices for additional info", lsblk_devices.len());
518+
log::debug!(
519+
"lsblk found {} devices for additional info",
520+
lsblk_devices.len()
521+
);
531522
self.merge_storage_info(&mut devices, lsblk_devices);
532523
}
533524

@@ -597,8 +588,7 @@ impl SystemInfoProvider for LinuxSystemInfoProvider {
597588
if lspci_output.success {
598589
let mut gpu_index = 0;
599590
for line in lspci_output.stdout.lines() {
600-
if line.to_lowercase().contains("vga")
601-
|| line.to_lowercase().contains("3d")
591+
if line.to_lowercase().contains("vga") || line.to_lowercase().contains("3d")
602592
{
603593
devices.push(GpuDevice {
604594
index: gpu_index,
@@ -634,8 +624,7 @@ impl SystemInfoProvider for LinuxSystemInfoProvider {
634624
}
635625
})?;
636626

637-
let mut interfaces =
638-
parse_ip_output(&ip_output.stdout).map_err(SystemError::ParseError)?;
627+
let mut interfaces = parse_ip_output(&ip_output.stdout).map_err(SystemError::ParseError)?;
639628

640629
// Enrich with sysfs data
641630
for iface in &mut interfaces {

src/domain/errors.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,13 @@ pub enum SystemError {
142142
/// I/O operation failed (simple)
143143
IoError(String),
144144
/// I/O operation failed (with path context)
145-
IoErrorWithPath {
146-
path: String,
147-
message: String,
148-
},
145+
IoErrorWithPath { path: String, message: String },
149146
/// Parsing error
150147
ParseError(String),
151148
/// Timeout
152149
Timeout(String),
153150
/// Resource not available
154-
NotAvailable {
155-
resource: String,
156-
},
151+
NotAvailable { resource: String },
157152
}
158153

159154
impl fmt::Display for SystemError {

src/domain/parsers/cpu.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn parse_sysfs_freq_khz(content: &str) -> Result<u32, String> {
5454
/// Size in KB.
5555
pub fn parse_sysfs_cache_size(content: &str) -> Result<u32, String> {
5656
let trimmed = content.trim();
57-
57+
5858
if trimmed.ends_with('K') || trimmed.ends_with('k') {
5959
let value: u32 = trimmed[..trimmed.len() - 1]
6060
.parse()
@@ -83,12 +83,12 @@ pub fn parse_sysfs_cache_size(content: &str) -> Result<u32, String> {
8383
/// * `content` - Content of /proc/cpuinfo
8484
pub fn parse_proc_cpuinfo(content: &str) -> Result<CpuInfo, String> {
8585
let mut cpu_info = CpuInfo::default();
86-
86+
8787
for line in content.lines() {
8888
if let Some((key, value)) = line.split_once(':') {
8989
let key = key.trim();
9090
let value = value.trim();
91-
91+
9292
match key {
9393
"vendor_id" => cpu_info.vendor = value.to_string(),
9494
"model name" => {
@@ -115,7 +115,7 @@ pub fn parse_proc_cpuinfo(content: &str) -> Result<CpuInfo, String> {
115115
}
116116
}
117117
}
118-
118+
119119
Ok(cpu_info)
120120
}
121121

src/domain/parsers/gpu.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ pub fn parse_lspci_gpu_output(output: &str) -> Result<Vec<GpuDevice>, String> {
108108

109109
for line in output.lines() {
110110
let line_lower = line.to_lowercase();
111-
111+
112112
// Look for VGA compatible or 3D controller
113113
if !line_lower.contains("vga") && !line_lower.contains("3d") {
114114
continue;
115115
}
116116

117117
// Extract PCI ID from brackets like [10de:2204]
118118
let pci_id = extract_pci_id(line);
119-
119+
120120
// Determine vendor from PCI ID
121121
let (vendor_enum, vendor_name) = if let Some(ref pci) = pci_id {
122122
let vendor_id = pci.split(':').next().unwrap_or("");
@@ -161,13 +161,13 @@ fn extract_pci_id(line: &str) -> Option<String> {
161161
let abs_start = search_start + start;
162162
if let Some(end) = line[abs_start..].find(']') {
163163
let bracket_content = &line[abs_start + 1..abs_start + end];
164-
164+
165165
// Check if it looks like a PCI ID (4 hex chars : 4 hex chars)
166166
if bracket_content.len() == 9 && bracket_content.chars().nth(4) == Some(':') {
167167
// Verify it's all hex chars
168168
let parts: Vec<&str> = bracket_content.split(':').collect();
169-
if parts.len() == 2
170-
&& parts[0].len() == 4
169+
if parts.len() == 2
170+
&& parts[0].len() == 4
171171
&& parts[1].len() == 4
172172
&& parts[0].chars().all(|c| c.is_ascii_hexdigit())
173173
&& parts[1].chars().all(|c| c.is_ascii_hexdigit())
@@ -191,7 +191,7 @@ mod tests {
191191
fn test_parse_nvidia_smi_output() {
192192
let output = "0, NVIDIA GeForce RTX 3090, GPU-12345678-1234-1234-1234-123456789012, 24576, 24000, 00000000:01:00.0, 535.129.03, 8.6";
193193
let devices = parse_nvidia_smi_output(output).unwrap();
194-
194+
195195
assert_eq!(devices.len(), 1);
196196
assert_eq!(devices[0].name, "NVIDIA GeForce RTX 3090");
197197
assert_eq!(devices[0].memory_total_mb, 24576);
@@ -202,9 +202,9 @@ mod tests {
202202
fn test_parse_lspci_gpu_output() {
203203
let output = r#"01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA102 [GeForce RTX 3090] [10de:2204] (rev a1)
204204
00:02.0 VGA compatible controller [0300]: Intel Corporation Device [8086:9a49] (rev 01)"#;
205-
205+
206206
let devices = parse_lspci_gpu_output(output).unwrap();
207-
207+
208208
assert_eq!(devices.len(), 2);
209209
assert_eq!(devices[0].vendor, "NVIDIA");
210210
assert_eq!(devices[1].vendor, "Intel");
@@ -213,7 +213,10 @@ mod tests {
213213
#[test]
214214
fn test_extract_pci_id() {
215215
assert_eq!(extract_pci_id("[10de:2204]"), Some("10de:2204".to_string()));
216-
assert_eq!(extract_pci_id("NVIDIA [10de:2204] (rev a1)"), Some("10de:2204".to_string()));
216+
assert_eq!(
217+
extract_pci_id("NVIDIA [10de:2204] (rev a1)"),
218+
Some("10de:2204".to_string())
219+
);
217220
assert_eq!(extract_pci_id("No PCI ID here"), None);
218221
}
219222
}

src/domain/parsers/storage.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pub fn is_virtual_device(name: &str) -> bool {
7575
///
7676
/// * `output` - JSON output from `lsblk -J -b -d -o NAME,SIZE,TYPE,MODEL,SERIAL,ROTA,TRAN,WWN`
7777
pub fn parse_lsblk_json(output: &str) -> Result<Vec<StorageDevice>, String> {
78-
let json: serde_json::Value = serde_json::from_str(output)
79-
.map_err(|e| format!("Failed to parse lsblk JSON: {}", e))?;
78+
let json: serde_json::Value =
79+
serde_json::from_str(output).map_err(|e| format!("Failed to parse lsblk JSON: {}", e))?;
8080

8181
let blockdevices = json
8282
.get("blockdevices")
@@ -97,10 +97,7 @@ pub fn parse_lsblk_json(output: &str) -> Result<Vec<StorageDevice>, String> {
9797
continue;
9898
}
9999

100-
let size_bytes = device
101-
.get("size")
102-
.and_then(|v| v.as_u64())
103-
.unwrap_or(0);
100+
let size_bytes = device.get("size").and_then(|v| v.as_u64()).unwrap_or(0);
104101

105102
// Skip small devices
106103
if size_bytes < 1_000_000_000 {

0 commit comments

Comments
 (0)