battery

Struct Battery

Source
pub struct Battery(/* private fields */)
where
    SysFsDevice: BatteryDevice;
Expand description

Battery instant information representation.

Consequent calls of the same method will return the same value.
See the Manager::refresh method, which can be used to update information hold in the current Battery.

Almost all methods are returning values in the SI measurement units, represented as a units from the uom crate.
If you are unfamiliar with uom, check the units module documentation for a few examples of how to get the values from them.

Implementations§

Source§

impl Battery

Source

pub fn state_of_charge(&self) -> Ratio

Battery state of charge.

The State of Charge (or SOC) is an expression of the battery capacity as a percentage of maximum capacity.

In plain english: it is how much energy your battery has (expressed in percents). This is an exactly that value which operating systems and desktop managers are displaying in the taskbar near the clock.

Roughly it can be calculated as battery.energy() / battery.energy_full(), but you should always use Battery::state_of_charge instead of the manual calculation, because many device drivers are providing this value more precisely, and this method takes that into account.

See also:

Source

pub fn energy(&self) -> Energy

Amount of energy currently available in the battery.

Source

pub fn energy_full(&self) -> Energy

Amount of energy in the battery when it’s considered full.

Source

pub fn energy_full_design(&self) -> Energy

Amount of energy the battery is designed to hold when it’s considered full.

Source

pub fn energy_rate(&self) -> Power

Amount of energy being drained from the battery.

Source

pub fn voltage(&self) -> ElectricPotential

Battery voltage.

Source

pub fn state_of_health(&self) -> Ratio

Gets battery state of health.

The State of Health (or SOH) is an indication of the point which has been reached in the life cycle of the battery and a measure of its condition relative to a fresh battery.

In plain english: this is how much energy in percents your battery can hold when fully charged. New battery - 100 %, old and degraded battery - notably lower amount of percents. See also:

Source

pub fn state(&self) -> State

Battery current state.

See State enum for possible values.

Source

pub fn technology(&self) -> Technology

Battery technology.

See Technology enum for possible values.

Source

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

Battery temperature.

Source

pub fn cycle_count(&self) -> Option<u32>

Number of charge/discharge cycles.

Source

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

Battery vendor.

Source

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

Battery model.

Source

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

Battery serial number.

Source

pub fn time_to_full(&self) -> Option<Time>

Remaining time till full battery.

This is an instant value and may different vastly from call to call. Any aggregation should be made by caller.

If battery is not charging at the moment, this method will return None.

Source

pub fn time_to_empty(&self) -> Option<Time>

Remaining time till empty battery.

This is an instant value and may different vastly from call to call. Any aggregation should be made by caller.

If battery is not discharging at the moment, this method will return None.

Trait Implementations§

Source§

impl Debug for Battery

Source§

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

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

impl Deref for Battery

Source§

type Target = SysFsDevice

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Battery

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Battery
where SysFsDevice: Sized,

§

impl !RefUnwindSafe for Battery

§

impl Send for Battery
where SysFsDevice: Sized,

§

impl Sync for Battery
where SysFsDevice: Sized,

§

impl Unpin for Battery
where SysFsDevice: Sized,

§

impl !UnwindSafe for Battery

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.