Crate hardware_query

Source
Expand description

§Hardware Query

A cross-platform Rust library for querying detailed system hardware information. Provides a unified interface to access CPU, GPU, memory, disk, network, and other hardware specifications across Windows, Linux, and macOS.

§Architecture

This library uses a modular architecture:

  • Core modules (cpu, gpu, memory, etc.) provide platform-agnostic interfaces
  • Platform-specific implementations in the platform module handle OS-specific detection
  • Features flags enable optional vendor-specific hardware detection

§Platform Support

  • Windows: Uses Windows Management Instrumentation (WMI) and native Windows APIs
  • Linux: Utilizes /proc, /sys filesystems and platform-specific commands
  • macOS: Leverages Core Foundation, IOKit and system commands

§Performance Considerations

Hardware detection operations can be relatively expensive, especially on first run. Consider caching the results when appropriate rather than querying repeatedly.

§Thread Safety

All public types in this library are Send and Sync unless explicitly documented otherwise. The library is designed to be used safely in multithreaded environments.

§Features

  • Cross-platform hardware detection (Windows, Linux, macOS)
  • Detailed CPU information (cores, threads, cache, features)
  • GPU detection and capabilities (CUDA, ROCm, DirectML support)
  • Memory configuration and status
  • Storage device enumeration and properties
  • Network interface detection and capabilities
  • Hardware acceleration support detection
  • Battery status and health monitoring
  • Thermal sensors and fan control (where available)
  • PCI/USB device enumeration
  • Serializable hardware information

§Example

use hardware_query::HardwareInfo;

// Get complete system information
let hw_info = HardwareInfo::query()?;

// Access CPU information
let cpu = hw_info.cpu();
println!("CPU: {} {} with {} cores, {} threads",
    cpu.vendor(),
    cpu.model_name(),
    cpu.physical_cores(),
    cpu.logical_cores()
);

// Check for specific CPU features
if cpu.has_feature("avx2") {
    println!("CPU supports AVX2 instructions");
}

// Get GPU information
for (i, gpu) in hw_info.gpus().iter().enumerate() {
    println!("GPU {}: {} {} with {} GB VRAM",
        i + 1,
        gpu.vendor(),
        gpu.model_name(),
        gpu.memory_gb()
    );
}

// Check specialized hardware
if !hw_info.npus().is_empty() {
    println!("NPUs detected: {} units", hw_info.npus().len());
}

if !hw_info.tpus().is_empty() {
    println!("TPUs detected: {} units", hw_info.tpus().len());
}

// Check ARM-specific hardware (Raspberry Pi, Jetson, etc.)
if let Some(arm) = hw_info.arm_hardware() {
    println!("ARM System: {}", arm.system_type);
}

// Check FPGA hardware
if !hw_info.fpgas().is_empty() {
    println!("FPGAs detected: {} units", hw_info.fpgas().len());
}

// Get system summary
let summary = hw_info.summary();
println!("System Summary:\n{}", summary);

Modules§

platform

Structs§

ARMHardwareInfo
ARM hardware information
BatteryInfo
Battery information
CPUInfo
CPU information and specifications
FPGAInfo
FPGA accelerator information
FanInfo
Fan information
GPUInfo
GPU information and specifications
HardwareInfo
Complete system hardware information
MemoryInfo
System memory information
NPUInfo
NPU information structure
NetworkInfo
Network interface information
PCIDevice
PCI device information
PowerInfo
Power consumption and thermal information
StorageInfo
Storage device information
TPUInfo
TPU information structure
ThermalInfo
System thermal information
ThermalSensor
Thermal sensor information
USBDevice
USB device information

Enums§

ARMSystemType
ARM-based system type
BatteryStatus
Battery status
CPUFeature
CPU feature flags
CPUVendor
CPU vendor information
FPGAFamily
FPGA family/series information
FPGAInterface
FPGA interface type
FPGAVendor
FPGA vendor information
GPUType
GPU type classification
GPUVendor
GPU vendor information
HardwareQueryError
Error types that can occur during hardware querying
MemoryType
Memory type classification
NPUArchitecture
NPU architecture information
NPUType
NPU type classification
NPUVendor
NPU vendor information
NetworkType
Network interface type
StorageType
Storage device type
TPUArchitecture
TPU generation and architecture
TPUConnectionType
TPU connection type
TPUVendor
TPU vendor information

Type Aliases§

Result
Result type for hardware query operations