heim_sensors/
temperatures.rs1use std::fmt;
2
3use heim_common::prelude::*;
4use heim_common::units::ThermodynamicTemperature;
5
6use crate::sys;
7
8pub struct TemperatureSensor {
10 pub(crate) unit: String,
11 pub(crate) label: Option<String>,
12 pub(crate) current: ThermodynamicTemperature,
13 pub(crate) high: Option<ThermodynamicTemperature>,
14 pub(crate) critical: Option<ThermodynamicTemperature>,
15}
16
17impl TemperatureSensor {
18 pub fn unit(&self) -> &str {
20 &self.unit
21 }
22
23 #[allow(clippy::option_as_ref_deref)] pub fn label(&self) -> Option<&str> {
26 self.label.as_ref().map(|s| s.as_str())
27 }
28
29 pub fn current(&self) -> ThermodynamicTemperature {
31 self.current
32 }
33
34 pub fn high(&self) -> Option<ThermodynamicTemperature> {
36 self.high
37 }
38
39 pub fn critical(&self) -> Option<ThermodynamicTemperature> {
41 self.critical
42 }
43}
44
45impl fmt::Debug for TemperatureSensor {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47 f.debug_struct("TemperatureSensor")
48 .field("unit", &self.unit())
49 .field("label", &self.label())
50 .field("current", &self.current())
51 .field("high", &self.high())
52 .field("critical", &self.critical())
53 .finish()
54 }
55}
56
57pub fn temperatures() -> impl Stream<Item = Result<TemperatureSensor>> {
66 sys::temperatures()
67}