如何在 Rust 中获取 PC CPU 的温度?
我最终想每五分钟获取一次温度(以摄氏度为单位)并将其记录到控制台。
我的目标是 Windows 10 20H2 并且有 Rust 版本
1.75.0
。
尝试这样的事情:
use std::{thread, time::Duration};
use sysinfo::{System, SystemExt, ComponentExt};
fn main() {
let mut system= System::new_all();
loop {
system.refresh_components();
let cpu_temp = system.get_components()
.iter()
.filter(|component| component.get_label().contains("CPU"))
.map(|component| component.get_temperature())
.next();
match cpu_temp {
Some(temp) => println!("Temp. of CPU: {:.2} °C", temp),
None => println!("temperature not available."),
}
thread::sleep(Duration::from_secs(300));
}
}