Skip to main content

BatterySnapshot

Struct BatterySnapshot 

Source
pub struct BatterySnapshot {
    pub charge: Percent,
    pub state: ChargeState,
    pub time_remaining: MetricState<Duration>,
    pub cycle_count: MetricState<u32>,
    pub capacity: MetricState<BatteryCapacity>,
    pub temperature_celsius: MetricState<f32>,
    pub power_watts: MetricState<f32>,
}
Expand description

Battery state.

Fields§

§charge: Percent

Charge level.

§state: ChargeState

Charging state.

§time_remaining: MetricState<Duration>

Time to empty while discharging, or to full while charging.

Only ever what the platform itself reports. §4 forbids deriving one from a single sample: a figure computed from one instantaneous current reading swings by hours between consecutive samples, and a monitor that showed it would be inventing the one number users trust most.

§cycle_count: MetricState<u32>

Charge cycles, where reported.

§capacity: MetricState<BatteryCapacity>

Design capacity beside present full-charge capacity, i.e. wear.

§temperature_celsius: MetricState<f32>

Cell temperature in degrees Celsius, where the pack reports one.

Separate from SensorSnapshot::temperatures because it is not a machine sensor: it describes the pack, and a battery pack at 45 °C means something quite different from a CPU package at 45 °C.

§power_watts: MetricState<f32>

Instantaneous power flowing through the pack, in watts.

A magnitude, never signed. Direction is BatterySnapshot::state’s job: the sign of Linux’s current_now is driver-dependent, so a signed watt figure here would mean “out” on one laptop and “in” on the next.

Implementations§

Source§

impl BatterySnapshot

Source

pub fn health(&self) -> MetricState<Percent>

Battery health, derived from the capacity pair and from nothing else.

A method rather than a field so there is no way to store a health figure that contradicts the capacities beside it. An unavailable capacity keeps its own reason, so “no capacity reported” and “capacity refused” stay distinguishable on screen (§4).

Trait Implementations§

Source§

impl Clone for BatterySnapshot

Source§

fn clone(&self) -> BatterySnapshot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BatterySnapshot

Source§

impl Debug for BatterySnapshot

Source§

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

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

impl PartialEq for BatterySnapshot

Source§

fn eq(&self, other: &BatterySnapshot) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BatterySnapshot

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.