Trait libmacchina::traits::BatteryReadout[][src]

pub trait BatteryReadout {
    fn new() -> Self;

    fn percentage(&self) -> Result<u8, ReadoutError> { ... }
fn status(&self) -> Result<BatteryState, ReadoutError> { ... } }

This trait provides the necessary functions for querying battery statistics from the host computer. A desktop computer might not be able to provide values such as percentage and status, which means a ReadoutError can be returned.

Example

use libmacchina::traits::BatteryReadout;
use libmacchina::traits::ReadoutError;
use libmacchina::traits::BatteryState;

//You can add fields to this struct which will then need to be initialized in the
//BatteryReadout::new() function.
pub struct MacOSBatteryReadout;

impl BatteryReadout for MacOSBatteryReadout {
    fn new() -> Self {
        MacOSBatteryReadout {}
    }

    fn percentage(&self) -> Result<u8, ReadoutError> {
        //get the battery percentage somehow...
        Ok(100u8) //always fully charged
    }

    fn status(&self) -> Result<BatteryState, ReadoutError> {
        //check if battery is being charged...
        Ok(BatteryState::Charging) //always charging.
    }
}

Required methods

fn new() -> Self[src]

Creates a new instance of the structure which implements this trait.

Loading content...

Provided methods

fn percentage(&self) -> Result<u8, ReadoutError>[src]

This function is used for querying the current battery percentage. The expected value is a u8 in the range of 0 to 100.

fn status(&self) -> Result<BatteryState, ReadoutError>[src]

This function is used for querying the current battery charging state. If the battery is currently being charged, we expect a return value of BatteryState::Charging, otherwise BatteryState::Discharging.

Loading content...

Implementors

Loading content...