summaryrefslogtreecommitdiffstats
path: root/third_party/rust/libudev/examples/list_devices.rs
blob: 5ef71765de194f68e12b2dd1acf87867813d87e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extern crate libudev;

use std::io;

fn main() {
    let context = libudev::Context::new().unwrap();
    list_devices(&context).unwrap();
}

fn list_devices(context: &libudev::Context) -> io::Result<()> {
    let mut enumerator = try!(libudev::Enumerator::new(&context));

    for device in try!(enumerator.scan_devices()) {
        println!("");
        println!("initialized: {:?}", device.is_initialized());
        println!("     devnum: {:?}", device.devnum());
        println!("    syspath: {:?}", device.syspath());
        println!("    devpath: {:?}", device.devpath());
        println!("  subsystem: {:?}", device.subsystem());
        println!("    sysname: {:?}", device.sysname());
        println!("     sysnum: {:?}", device.sysnum());
        println!("    devtype: {:?}", device.devtype());
        println!("     driver: {:?}", device.driver());
        println!("    devnode: {:?}", device.devnode());

        if let Some(parent) = device.parent() {
            println!("     parent: {:?}", parent.syspath());
        }
        else {
            println!("     parent: None");
        }

        println!("  [properties]");
        for property in device.properties() {
            println!("    - {:?} {:?}", property.name(), property.value());
        }

        println!("  [attributes]");
        for attribute in device.attributes() {
            println!("    - {:?} {:?}", attribute.name(), attribute.value());
        }
    }

    Ok(())
}