Struct thermal_config::ThermalConfig

source ·
pub struct ThermalConfig { /* private fields */ }
Expand description

This library is used to parse a thermal configuration JSON file into a data structure which also implements some convenience methods for accessing and consuming the data.

The intended usage is that ThermalConfig::read() is called with a thermal configuration JSON file path. If successful, the function returns a ThermalConfig instance containing the parsed config data.

The parser expects a JSON5 file of the following format: { clients: { audio: [ { state: 1, trip_points: [ { sensor_name: ‘CPU thermal’, activate_at: 75, deactivate_below: 71, }, ], }, { state: 2, trip_points: [ { sensor_name: ‘CPU thermal’, activate_at: 86, deactivate_below: 82, }, ], }, ], }, } Represents the top level of a thermal configuration structure.

Implementations§

source§

impl ThermalConfig

source

pub fn new() -> Self

Creates a new, empty ThermalConfig instance.

An empty ThermalConfig instance corresponds to the case where no client has specified a thermal trip point configuration.

Note: this is only intended for use in tests. However, it isn’t marked as cfg(test) so that code outside of the library can use it in their tests as well.

source

pub fn read(json_file_path: &Path) -> Result<ThermalConfig, Error>

Read the supplied JSON file path and parse into a ThermalConfig instance.

Attempts to open, read, and parse the supplied JSON file into a valid ThermalConfig instance. If a ThermalConfig instance could be created with the JSON configuration, then it is also tested for validity. If a ThermalConfig instance could not be created, or validation fails, then an error is returned.

source

pub fn validate(&self) -> Result<(), Error>

Validates the thermal configuration.

source

pub fn add_client_config(self, client: &str, config: ClientConfig) -> Self

Adds a configuration entry for the specified client.

Note: this is only intended for use in tests. However, it isn’t marked as cfg(test) so that code outside of the library can use it in their tests as well.

source

pub fn get_client_config(&self, client: &String) -> Option<&ClientConfig>

Gets the ClientConfig instance for the specified client.

source

pub fn into_iter(self) -> impl Iterator<Item = (String, ClientConfig)>

Trait Implementations§

source§

impl Debug for ThermalConfig

source§

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

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

impl<'de> Deserialize<'de> for ThermalConfig

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,