hardware_query/
lib.rs

1//! # Hardware Query
2//!
3//! **The easiest way to get hardware information in Rust.**
4//!
5//! This crate provides a simple, cross-platform API for hardware detection and system monitoring.
6//! Whether you need a quick system overview or detailed hardware analysis, there's an API tier for you.
7//!
8//! ## Quick Start (1 line of code)
9//!
10//! Get a complete system overview with health status:
11//!
12//! ```rust
13//! use hardware_query::SystemOverview;
14//! 
15//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
16//! let overview = SystemOverview::quick()?;
17//! println!("{}", overview);  // Formatted system summary with health status
18//! # Ok(())
19//! # }
20//! ```
21//!
22//! ## Domain-Specific Presets (2-3 lines)
23//!
24//! Get assessments tailored to your use case:
25//!
26//! ```rust
27//! use hardware_query::HardwarePresets;
28//!
29//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
30//! // For AI/ML applications
31//! let ai_assessment = HardwarePresets::ai_assessment()?;
32//! println!("AI Score: {}/100", ai_assessment.ai_score);
33//! println!("Supported Frameworks: {:?}", ai_assessment.frameworks);
34//!
35//! // For gaming applications  
36//! let gaming_assessment = HardwarePresets::gaming_assessment()?;
37//! println!("Gaming Score: {}/100", gaming_assessment.gaming_score);
38//! println!("Recommended Settings: {}", gaming_assessment.recommended_settings);
39//!
40//! // For development environments
41//! let dev_assessment = HardwarePresets::developer_assessment()?;
42//! println!("Build Performance: {:?}", dev_assessment.build_performance);
43//! # Ok(())
44//! # }
45//! ```
46//!
47//! ## Custom Queries (3-5 lines)
48//!
49//! Build exactly the hardware query you need:
50//!
51//! ```rust
52//! use hardware_query::HardwareQueryBuilder;
53//!
54//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
55//! // Get basic system info
56//! let basic_info = HardwareQueryBuilder::new()
57//!     .with_basic()
58//!     .cpu_and_memory()?;
59//!
60//! // Get AI-focused hardware info
61//! let ai_info = HardwareQueryBuilder::new()
62//!     .with_ai_focused()
63//!     .gpu_and_accelerators()?;
64//!
65//! // Get everything for system monitoring
66//! let monitoring_info = HardwareQueryBuilder::new()
67//!     .with_monitoring()
68//!     .all_hardware()?;
69//! # Ok(())
70//! # }
71//! ```
72//!
73//! ## Complete Hardware Analysis (Advanced)
74//!
75//! For detailed hardware analysis and custom processing:
76//!
77//! ```rust
78//! use hardware_query::HardwareInfo;
79//!
80//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
81//! // Get complete system information
82//! let hw_info = HardwareInfo::query()?;
83//!
84//! // Access detailed CPU information
85//! let cpu = hw_info.cpu();
86//! println!("CPU: {} {} - {} cores, {} threads",
87//!     cpu.vendor(),
88//!     cpu.model_name(),
89//!     cpu.physical_cores(),
90//!     cpu.logical_cores()
91//! );
92//!
93//! // Check specific CPU features for optimization
94//! if cpu.has_feature("avx2") && cpu.has_feature("fma") {
95//!     println!("CPU optimized for SIMD operations");
96//! }
97//!
98//! // Analyze GPU capabilities for AI workloads
99//! for gpu in hw_info.gpus() {
100//!     println!("GPU: {} {} - {} GB VRAM", 
101//!         gpu.vendor(), gpu.model_name(), gpu.memory_gb());
102//!     
103//!     if gpu.supports_cuda() {
104//!         println!("  CUDA support available");
105//!     }
106//!     if gpu.supports_opencl() {
107//!         println!("  OpenCL support available");
108//!     }
109//! }
110//!
111//! // Check for specialized AI hardware
112//! if !hw_info.npus().is_empty() {
113//!     println!("AI accelerators found: {} NPUs", hw_info.npus().len());
114//! }
115//!
116//! // Memory analysis for performance optimization
117//! let memory = hw_info.memory();
118//! println!("Memory: {} GB total, {} GB available",
119//!     memory.total_gb(),
120//!     memory.available_gb()
121//! );
122//!
123//! // Storage performance characteristics
124//! for storage in hw_info.storage() {
125//!     println!("Storage: {} - {} GB ({})",
126//!         storage.model(),
127//!         storage.capacity_gb(),
128//!         if storage.is_ssd() { "SSD" } else { "HDD" }
129//!     );
130//! }
131//! # Ok(())
132//! # }
133//! ```
134//!
135//! ## Monitoring and Real-time Updates
136//!
137//! For applications that need continuous hardware monitoring:
138//!
139//! ```rust,no_run
140//! #[cfg(feature = "monitoring")]
141//! use hardware_query::{HardwareMonitor, MonitoringConfig};
142//!
143//! # #[cfg(feature = "monitoring")]
144//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
145//! let config = MonitoringConfig::new()
146//!     .with_cpu_monitoring(true)
147//!     .with_thermal_monitoring(true)
148//!     .with_interval_ms(1000);
149//!
150//! let mut monitor = HardwareMonitor::new(config);
151//!
152//! monitor.start_monitoring(|event| {
153//!     match event {
154//!         hardware_query::MonitoringEvent::TemperatureAlert { component, temp } => {
155//!             println!("Warning: {} temperature: {}°C", component, temp);
156//!         }
157//!         hardware_query::MonitoringEvent::CpuUsageHigh { usage } => {
158//!             println!("High CPU usage: {}%", usage);
159//!         }
160//!         _ => {}
161//!     }
162//! })?;
163//! # Ok(())
164//! # }
165//! ```
166//!
167//! ## Feature Flags
168//!
169//! - **Default**: Basic hardware detection (CPU, Memory, GPU, Storage)
170//! - **`monitoring`**: Real-time monitoring capabilities, thermal sensors, power management
171//! - **`serde`**: Serialization/deserialization support (automatically enabled)
172//!
173//! ## Platform Support
174//!
175//! - **Windows**: Native WMI and Windows API support
176//! - **Linux**: Comprehensive `/proc`, `/sys` filesystem support  
177//! - **macOS**: IOKit and system framework integration
178//!
179//! All APIs work consistently across platforms, with graceful degradation when specific hardware isn't available.
180
181mod battery;
182mod cpu;
183mod error;
184mod gpu;
185mod hardware_info;
186mod memory;
187mod network;
188mod npu;
189mod pci;
190pub mod platform;
191mod storage;
192mod thermal;
193mod tpu;
194mod usb;
195mod arm;
196mod fpga;
197mod power;
198mod virtualization;
199
200#[cfg(feature = "monitoring")]
201mod monitoring;
202
203// Simplified API modules
204pub mod simple;
205pub mod builder;
206pub mod presets;
207
208pub use battery::{BatteryInfo, BatteryStatus};
209pub use cpu::{CPUFeature, CPUInfo, CPUVendor};
210pub use error::{HardwareQueryError, Result};
211pub use gpu::{GPUInfo, GPUType, GPUVendor};
212pub use hardware_info::HardwareInfo;
213pub use memory::{MemoryInfo, MemoryType};
214pub use network::{NetworkInfo, NetworkType};
215pub use npu::{NPUInfo, NPUVendor, NPUType, NPUArchitecture};
216pub use pci::PCIDevice;
217pub use storage::{StorageInfo, StorageType};
218pub use thermal::{FanInfo, ThermalInfo, ThermalSensor, ThrottlingPrediction, CoolingRecommendation, ThrottlingSeverity};
219pub use tpu::{TPUInfo, TPUVendor, TPUArchitecture, TPUConnectionType};
220pub use usb::USBDevice;
221pub use arm::{ARMHardwareInfo, ARMSystemType, PowerInfo};
222pub use fpga::{FPGAInfo, FPGAVendor, FPGAFamily, FPGAInterface};
223pub use power::{PowerProfile, PowerState, ThrottlingRisk, PowerOptimization, OptimizationCategory};
224pub use virtualization::{VirtualizationInfo, VirtualizationType, ContainerRuntime, ResourceLimits};
225
226#[cfg(feature = "monitoring")]
227pub use monitoring::{HardwareMonitor, MonitoringConfig, MonitoringEvent, MonitoringStats, MonitoringCallback};
228
229// Simplified API exports - these are the recommended entry points for most users
230pub use simple::{SystemOverview, SimpleCPU, SimpleGPU, SimpleStorage, SystemHealth, 
231                 HealthStatus, TemperatureStatus, PowerStatus};
232pub use builder::{HardwareQueryBuilder, CustomHardwareInfo};
233pub use presets::{HardwarePresets, AIHardwareAssessment, GamingHardwareAssessment, 
234                  DeveloperHardwareAssessment, ServerHardwareAssessment};