#[cfg_attr(target_os = "macos", path = "gpu/macos.rs")]
#[cfg_attr(target_os = "windows", path = "gpu/windows.rs")]
#[cfg_attr(target_os = "linux", path = "gpu/linux.rs")]
#[cfg_attr(
not(any(target_os = "macos", target_os = "windows", target_os = "linux")),
path = "gpu/unsupported.rs"
)]
mod platform;
pub(crate) struct GpuProbe(platform::Probe);
impl GpuProbe {
pub(crate) fn new() -> Option<Self> {
platform::Probe::new().map(Self)
}
pub(crate) fn sample(&mut self) -> Option<f32> {
self.0.sample().map(|percent| percent.clamp(0., 100.))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_reading_is_a_percentage() {
let Some(mut probe) = GpuProbe::new() else {
return;
};
if let Some(percent) = probe.sample() {
assert!(
(0. ..=100.).contains(&percent),
"{percent} is not a percentage"
);
}
}
}