[go: up one dir, main page]

Component

Struct Component 

Source
pub struct Component { /* private fields */ }
Expand description

Getting a component temperature information.

use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    if let Some(temperature) = component.temperature() {
        println!("{} {temperature}°C", component.label());
    } else {
        println!("{} (unknown temperature)", component.label());
    }
}

Implementations§

Source§

impl Component

Source

pub fn temperature(&self) -> Option<f32>

Returns the temperature of the component (in celsius degree).

§Linux

Returns f32::NAN if it failed to retrieve it.

use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    if let Some(temperature) = component.temperature() {
        println!("{temperature}°C");
    }
}
Source

pub fn max(&self) -> Option<f32>

Returns the maximum temperature of the component (in celsius degree).

Note: if temperature is higher than the current max, max value will be updated on refresh.

§Linux

May be computed by sysinfo from kernel. Returns f32::NAN if it failed to retrieve it.

use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    if let Some(max) = component.max() {
        println!("{max}°C");
    }
}
Source

pub fn critical(&self) -> Option<f32>

Returns the highest temperature before the component halts (in celsius degree).

§Linux

Critical threshold defined by chip or kernel.

use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    if let Some(critical) = component.critical() {
        println!("{critical}°C");
    }
}
Source

pub fn label(&self) -> &str

Returns the label of the component.

§Linux

Since components information is retrieved thanks to hwmon, the labels are generated as follows. Note: it may change and it was inspired by sensors own formatting.

namelabeldevice_modelid_sensorComputed label by sysinfo
"{name} {label} {device_model}"
"{name} {label}"
"{name} {device_model}"
"{name} temp{id}"
use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    println!("{}", component.label());
}
Source

pub fn id(&self) -> Option<&str>

Returns the identifier of the component.

Note: The identifier should be reasonably unique but is provided by the kernel. It could change if the hardware changes or after a reboot.

OSComputed ID by sysinfoExample
Linux/hwmonhwmon file concatenated with the temp index. hwmon0_1 if the temperature data comes from the hwmon0/temp1_input file.
Linux/thermalthermal file namethermal_zone0
FreeBSDcpu_ concatenated with the core index.cpu_1 for the first core.
macOS/armSerial ID reported by the HID driver.
macOS/x86Technical ID sent to the OS (see below)TXCX
WindowsComputer (same as the label)Computer
appstoreComponents are not availableNone
unknownComponents are not availableNone

For macOS on X86 the following identifiers are possible:

  • TXCX or TXCx for PECI CPU (depending on if run on iMac or MacBook)
  • TC0P for CPU Proximity
  • TG0P for GPU
  • TB0T for Battery
use sysinfo::Components;

let components = Components::new_with_refreshed_list();
for component in &components {
    if let Some(id) = component.id() {
        println!("{id}");
    }
}
Source

pub fn refresh(&mut self)

Refreshes component.

use sysinfo::Components;

let mut components = Components::new_with_refreshed_list();
for component in components.iter_mut() {
    component.refresh();
}

Trait Implementations§

Source§

impl Debug for Component

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Component

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Component

§

impl RefUnwindSafe for Component

§

impl Send for Component

§

impl Sync for Component

§

impl Unpin for Component

§

impl UnwindSafe for Component

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.