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);

Re-exports§

pub use simple::SystemOverview;
pub use simple::SimpleCPU;
pub use simple::SimpleGPU;
pub use simple::SimpleStorage;
pub use simple::SystemHealth;
pub use simple::HealthStatus;
pub use simple::TemperatureStatus;
pub use simple::PowerStatus;
pub use builder::HardwareQueryBuilder;
pub use builder::CustomHardwareInfo;
pub use presets::HardwarePresets;
pub use presets::AIHardwareAssessment;
pub use presets::GamingHardwareAssessment;
pub use presets::DeveloperHardwareAssessment;
pub use presets::ServerHardwareAssessment;

Modules§

builder
Hardware query builder for customizable hardware information gathering
platform
presets
Hardware query presets for common use cases
simple
Simplified hardware query interface

Structs§

ARMHardwareInfo
ARM hardware information
BatteryInfo
Battery information
CPUInfo
CPU information and specifications
ContainerRuntime
Container runtime information
CoolingRecommendation
Cooling optimization recommendation
FPGAInfo
FPGA accelerator information
FanInfo
Fan information
GPUInfo
GPU information and specifications
HardwareInfo
Complete system hardware information
HardwareMonitor
Real-time hardware monitor
MemoryInfo
System memory information
MonitoringConfig
Hardware monitoring configuration
MonitoringStats
Monitoring statistics
NPUInfo
NPU information structure
NetworkInfo
Network interface information
PCIDevice
PCI device information
PowerInfo
Power consumption and thermal information
PowerOptimization
Power optimization recommendation
PowerProfile
Power consumption profile for the system
ResourceLimits
Resource limits imposed by virtualization
StorageInfo
Storage device information
TPUInfo
TPU information structure
ThermalInfo
System thermal information
ThermalSensor
Thermal sensor information
ThrottlingPrediction
Thermal throttling prediction
USBDevice
USB device information
VirtualizationInfo
Virtualization environment 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
MonitoringEvent
Hardware monitoring event
NPUArchitecture
NPU architecture information
NPUType
NPU type classification
NPUVendor
NPU vendor information
NetworkType
Network interface type
OptimizationCategory
Category of power optimization
PowerState
Current system power state
StorageType
Storage device type
TPUArchitecture
TPU generation and architecture
TPUConnectionType
TPU connection type
TPUVendor
TPU vendor information
ThrottlingRisk
Risk level for thermal throttling
ThrottlingSeverity
Severity of thermal throttling
VirtualizationType
Type of virtualization environment

Traits§

MonitoringCallback
Hardware monitoring callback trait

Type Aliases§

Result
Result type for hardware query operations