BatteryStatus

Struct BatteryStatus 

Source
pub struct BatteryStatus {
    pub voltage_mv: Option<u16>,
    pub level_percent: Option<u8>,
    pub charge_state: Option<BatteryChargeState>,
}
Expand description

One battery status snapshot: the fields the platform reports.

None means the field is unsupported (its flag bit is clear). A snapshot with every field None encodes as the empty value.

Fields§

§voltage_mv: Option<u16>

Measured voltage at the battery terminals, in millivolts.

§level_percent: Option<u8>

Estimated state of charge, 0–100 percent.

§charge_state: Option<BatteryChargeState>

Charge state reported by the charging system.

Implementations§

Source§

impl BatteryStatus

Source

pub const fn is_empty(&self) -> bool

Whether no field is reported (the empty wire form).

Source

pub fn flags(&self) -> u8

The field-flags octet for this snapshot.

Source

pub fn encode(&self, out: &mut [u8]) -> Result<usize, BatteryError>

Encode the snapshot, returning the number of bytes written.

An all-None snapshot encodes as zero bytes (the empty form). A level above 100 is rejected as BatteryError::Malformed.

Source

pub fn decode(value: &[u8]) -> Result<Self, BatteryError>

Strictly decode a property value.

The empty value decodes to an all-None snapshot. Any other value must consist of exactly the flags octet and the fields it declares; a zero flags octet, reserved bits, trailing bytes, a level above 100, and unknown charge-state codes are all malformed.

Trait Implementations§

Source§

impl Clone for BatteryStatus

Source§

fn clone(&self) -> BatteryStatus

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BatteryStatus

Source§

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

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

impl Default for BatteryStatus

Source§

fn default() -> BatteryStatus

Returns the “default value” for a type. Read more
Source§

impl PartialEq for BatteryStatus

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BatteryStatus

Source§

impl Eq for BatteryStatus

Source§

impl StructuralPartialEq for BatteryStatus

Auto Trait Implementations§

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

§

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
§

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.