use std::sync::OnceLock;
pub mod cpu;
pub mod drive;
pub mod io_primitives;
pub mod memory;
pub(crate) mod plp;
mod probe;
pub use crate::hardware::cpu::{CpuFeatures, CpuInfo};
pub use crate::hardware::drive::{DriveInfo, DriveKind};
pub use crate::hardware::io_primitives::IoPrimitives;
pub use crate::hardware::memory::MemoryInfo;
pub use crate::hardware::probe::PlpStatus;
#[derive(Debug, Clone)]
pub struct HardwareInfo {
pub drive: DriveInfo,
pub memory: MemoryInfo,
pub cpu: CpuInfo,
pub io_primitives: IoPrimitives,
}
static HARDWARE_INFO: OnceLock<HardwareInfo> = OnceLock::new();
static DRIVE_INFO: OnceLock<DriveInfo> = OnceLock::new();
static CPU_INFO: OnceLock<CpuInfo> = OnceLock::new();
static IO_PRIMITIVES: OnceLock<IoPrimitives> = OnceLock::new();
#[must_use]
pub fn info() -> &'static HardwareInfo {
HARDWARE_INFO.get_or_init(|| HardwareInfo {
drive: drive::probe(),
memory: memory::probe(),
cpu: cpu::probe(),
io_primitives: io_primitives::probe(),
})
}
#[must_use]
pub fn drive() -> &'static DriveInfo {
DRIVE_INFO.get_or_init(drive::probe)
}
#[must_use]
pub fn memory() -> MemoryInfo {
memory::probe()
}
#[must_use]
pub fn cpu() -> &'static CpuInfo {
CPU_INFO.get_or_init(cpu::probe)
}
#[must_use]
pub fn io_primitives() -> &'static IoPrimitives {
IO_PRIMITIVES.get_or_init(io_primitives::probe)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_info_returns_consistent_reference() {
let a = info() as *const HardwareInfo;
let b = info() as *const HardwareInfo;
assert_eq!(a, b);
}
#[test]
fn test_info_cpu_has_at_least_one_core() {
assert!(info().cpu.cores_logical >= 1);
}
#[test]
fn test_drive_returns_consistent_reference() {
let a = drive() as *const DriveInfo;
let b = drive() as *const DriveInfo;
assert_eq!(a, b);
}
#[test]
fn test_memory_does_not_cache_a_static_reference() {
let _: MemoryInfo = memory();
let _: MemoryInfo = memory();
}
#[test]
fn test_io_primitives_consistent_reference() {
let a = io_primitives() as *const IoPrimitives;
let b = io_primitives() as *const IoPrimitives;
assert_eq!(a, b);
}
}