我正在运行 Windows 10 20H2 并拥有 rustc 版本“1.75.0”。
我想要代码来查找PC CPU的温度,请帮忙。
我希望从正常运行时间起每 5 分钟获取一次电脑温度。
它应该以摄氏度登录到控制台。
尝试这样的事情: '''
使用 std::{thread, time::Duration};
使用 sysinfo::{System, SystemExt, ComponentExt};
fn main() { 让 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));
}
}'''