#glib #udev #ffi #api-bindings

gudev

Rust API for gudev, the glib support library for libudev

16 breaking releases

new 0.17.0 Nov 24, 2024
0.16.0 Mar 17, 2024
0.15.0 Aug 3, 2023
0.14.0 Feb 17, 2023
0.1.1 Nov 30, 2016

#470 in Hardware support

Download history 2/week @ 2024-09-17 71/week @ 2024-09-24 3/week @ 2024-11-05 96/week @ 2024-11-19

99 downloads per month
Used in gnome-egpu

MIT license

47KB
1K SLoC

gudev

gudev is a crate that provide Rust idiomatic bindings for GUDev.

It follows the release of glib-rs.

To use in your project, just add gudev = "^0.11.0" to your Cargo.toml.

Please file issues at:

https://github.com/hfiguiere/gudev-rs/

The latest autogenerated online documentation is at:

https://docs.rs/gudev/latest/gudev/


lib.rs:

Rust bindings for the gudev library.

Libgudev is a library providing GObject bindings for libudev.

Usage

Add the following to your Cargo.toml:

[dependencies]
gudev = "0.12"

Next:

use gudev::prelude::*;
use gudev::Client;
use gudev::Device;

fn main() {
    // Get a list of all block devices
    let devices = Client::new(&[]).query_by_subsystem(Some("block"));

    for device in devices {
        print_device(&device);
    }
}

fn print_device(device: &Device) {
    println!(
        "{} (subsystem={}, sysname={}, devtype={})",
        device.sysfs_path().unwrap_or_else(|| "---".into()),
        device.subsystem().unwrap_or_else(|| "---".into()),
        device.device_file().unwrap_or_else(|| "---".into()),
        device.devtype().unwrap_or_else(|| "---".into()),
    );
}

Dependencies

~5.5MB
~119K SLoC