#linux #battery #acpi

acpid_plug

Listen to AC adapter plug events from acpid

2 releases

new 0.1.2 Apr 5, 2024
0.1.1 Apr 5, 2024
0.1.0 Apr 5, 2024

#411 in Unix APIs

Download history 326/week @ 2024-04-03

326 downloads per month

MPL-2.0 license

11KB
81 lines

acpid-plug

Rust crate for listening to AC adapter plug events on Linux from acpid.

use futures_util::StreamExt;

#[tokio::main(flavor = "current_thread")]
async fn main() -> std::io::Result<()> {
    let mut ac_plug_events = acpid_plug::connect().await?;

    while let Some(event) = ac_plug_events.next().await {
        match event {
            Ok(event) => println!("{:?}", event),
            Err(why) => eprintln!("error: {}", why),
        }
    }

    Ok(())
}

lib.rs:

use futures_util::StreamExt;

#[tokio::main(flavor = "current_thread")]
async fn main() -> std::io::Result<()> {
    let mut ac_plug_events = acpid_plug::connect().await?;

    while let Some(event) = ac_plug_events.next().await {
        match event {
            Ok(event) => println!("{:?}", event),
            Err(why) => eprintln!("error: {}", why),
        }
    }

    Ok(())
}

Dependencies

~3–13MB
~120K SLoC