Struct Device

Source
pub struct Device { /* private fields */ }
Expand description

A structure that provides access to sysfs/kernel devices.

Implementations§

Source§

impl Device

Source

pub fn from_syspath(context: &Context, syspath: &Path) -> Result<Self>

Creates a device for a given syspath.

The syspath parameter should be a path to the device file within the sysfs file system, e.g., /sys/devices/virtual/tty/tty0.

Source

pub fn is_initialized(&self) -> bool

Checks whether the device has already been handled by udev.

When a new device is connected to the system, udev initializes the device by setting permissions, renaming network devices, and possibly other initialization routines. This method returns true if udev has performed all of its work to initialize this device.

This method only applies to devices with device nodes or network interfaces. All other devices return true by default.

Examples found in repository?
examples/list_devices.rs (line 15)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn devnum(&self) -> Option<dev_t>

Gets the device’s major/minor number.

Examples found in repository?
examples/list_devices.rs (line 16)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn syspath(&self) -> Option<&Path>

Returns the syspath of the device.

The path is an absolute path and includes the sys mount point. For example, the syspath for tty0 could be /sys/devices/virtual/tty/tty0, which includes the sys mount point, /sys.

Examples found in repository?
examples/monitor.rs (line 65)
39fn monitor(context: &libudev::Context) -> io::Result<()> {
40    let mut monitor = try!(libudev::Monitor::new(context));
41
42    try!(monitor.match_subsystem_devtype("usb", "usb_device"));
43    let mut socket = try!(monitor.listen());
44
45    let mut fds = vec!(pollfd { fd: socket.as_raw_fd(), events: POLLIN, revents: 0 });
46
47    loop {
48        let result = unsafe { ppoll((&mut fds[..]).as_mut_ptr(), fds.len() as nfds_t, ptr::null_mut(), ptr::null()) };
49
50        if result < 0 {
51            return Err(io::Error::last_os_error());
52        }
53
54        let event = match socket.receive_event() {
55            Some(evt) => evt,
56            None => {
57                thread::sleep(Duration::from_millis(10));
58                continue;
59            },
60        };
61
62        println!("{}: {} {} (subsystem={}, sysname={}, devtype={})",
63                 event.sequence_number(),
64                 event.event_type(),
65                 event.syspath().map_or("", |s| { s.to_str().unwrap_or("") }),
66                 event.subsystem().map_or("", |s| { s.to_str().unwrap_or("") }),
67                 event.sysname().map_or("", |s| { s.to_str().unwrap_or("") }),
68                 event.devtype().map_or("", |s| { s.to_str().unwrap_or("") }));
69    }
70}
More examples
Hide additional examples
examples/list_devices.rs (line 17)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn devpath(&self) -> Option<&OsStr>

Returns the kernel devpath value of the device.

The path does not contain the sys mount point, but does start with a /. For example, the devpath for tty0 could be /devices/virtual/tty/tty0.

Examples found in repository?
examples/list_devices.rs (line 18)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn devnode(&self) -> Option<&Path>

Returns the path to the device node belonging to the device.

The path is an absolute path and starts with the device directory. For example, the device node for tty0 could be /dev/tty0.

Examples found in repository?
examples/list_devices.rs (line 24)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn parent(&self) -> Option<Device>

Returns the parent of the device.

Examples found in repository?
examples/list_devices.rs (line 26)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn subsystem(&self) -> Option<&OsStr>

Returns the subsystem name of the device.

The subsystem name is a string that indicates which kernel subsystem the device belongs to. Examples of subsystem names are tty, vtconsole, block, scsi, and net.

Examples found in repository?
examples/monitor.rs (line 66)
39fn monitor(context: &libudev::Context) -> io::Result<()> {
40    let mut monitor = try!(libudev::Monitor::new(context));
41
42    try!(monitor.match_subsystem_devtype("usb", "usb_device"));
43    let mut socket = try!(monitor.listen());
44
45    let mut fds = vec!(pollfd { fd: socket.as_raw_fd(), events: POLLIN, revents: 0 });
46
47    loop {
48        let result = unsafe { ppoll((&mut fds[..]).as_mut_ptr(), fds.len() as nfds_t, ptr::null_mut(), ptr::null()) };
49
50        if result < 0 {
51            return Err(io::Error::last_os_error());
52        }
53
54        let event = match socket.receive_event() {
55            Some(evt) => evt,
56            None => {
57                thread::sleep(Duration::from_millis(10));
58                continue;
59            },
60        };
61
62        println!("{}: {} {} (subsystem={}, sysname={}, devtype={})",
63                 event.sequence_number(),
64                 event.event_type(),
65                 event.syspath().map_or("", |s| { s.to_str().unwrap_or("") }),
66                 event.subsystem().map_or("", |s| { s.to_str().unwrap_or("") }),
67                 event.sysname().map_or("", |s| { s.to_str().unwrap_or("") }),
68                 event.devtype().map_or("", |s| { s.to_str().unwrap_or("") }));
69    }
70}
More examples
Hide additional examples
examples/list_devices.rs (line 19)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn sysname(&self) -> Option<&OsStr>

Returns the kernel device name for the device.

The sysname is a string that differentiates the device from others in the same subsystem. For example, tty0 is the sysname for a TTY device that differentiates it from others, such as tty1.

Examples found in repository?
examples/monitor.rs (line 67)
39fn monitor(context: &libudev::Context) -> io::Result<()> {
40    let mut monitor = try!(libudev::Monitor::new(context));
41
42    try!(monitor.match_subsystem_devtype("usb", "usb_device"));
43    let mut socket = try!(monitor.listen());
44
45    let mut fds = vec!(pollfd { fd: socket.as_raw_fd(), events: POLLIN, revents: 0 });
46
47    loop {
48        let result = unsafe { ppoll((&mut fds[..]).as_mut_ptr(), fds.len() as nfds_t, ptr::null_mut(), ptr::null()) };
49
50        if result < 0 {
51            return Err(io::Error::last_os_error());
52        }
53
54        let event = match socket.receive_event() {
55            Some(evt) => evt,
56            None => {
57                thread::sleep(Duration::from_millis(10));
58                continue;
59            },
60        };
61
62        println!("{}: {} {} (subsystem={}, sysname={}, devtype={})",
63                 event.sequence_number(),
64                 event.event_type(),
65                 event.syspath().map_or("", |s| { s.to_str().unwrap_or("") }),
66                 event.subsystem().map_or("", |s| { s.to_str().unwrap_or("") }),
67                 event.sysname().map_or("", |s| { s.to_str().unwrap_or("") }),
68                 event.devtype().map_or("", |s| { s.to_str().unwrap_or("") }));
69    }
70}
More examples
Hide additional examples
examples/list_devices.rs (line 20)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn sysnum(&self) -> Option<usize>

Returns the instance number of the device.

The instance number is used to differentiate many devices of the same type. For example, /dev/tty0 and /dev/tty1 are both TTY devices but have instance numbers of 0 and 1, respectively.

Some devices don’t have instance numbers, such as /dev/console, in which case the method returns None.

Examples found in repository?
examples/list_devices.rs (line 21)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn devtype(&self) -> Option<&OsStr>

Returns the devtype name of the device.

Examples found in repository?
examples/monitor.rs (line 68)
39fn monitor(context: &libudev::Context) -> io::Result<()> {
40    let mut monitor = try!(libudev::Monitor::new(context));
41
42    try!(monitor.match_subsystem_devtype("usb", "usb_device"));
43    let mut socket = try!(monitor.listen());
44
45    let mut fds = vec!(pollfd { fd: socket.as_raw_fd(), events: POLLIN, revents: 0 });
46
47    loop {
48        let result = unsafe { ppoll((&mut fds[..]).as_mut_ptr(), fds.len() as nfds_t, ptr::null_mut(), ptr::null()) };
49
50        if result < 0 {
51            return Err(io::Error::last_os_error());
52        }
53
54        let event = match socket.receive_event() {
55            Some(evt) => evt,
56            None => {
57                thread::sleep(Duration::from_millis(10));
58                continue;
59            },
60        };
61
62        println!("{}: {} {} (subsystem={}, sysname={}, devtype={})",
63                 event.sequence_number(),
64                 event.event_type(),
65                 event.syspath().map_or("", |s| { s.to_str().unwrap_or("") }),
66                 event.subsystem().map_or("", |s| { s.to_str().unwrap_or("") }),
67                 event.sysname().map_or("", |s| { s.to_str().unwrap_or("") }),
68                 event.devtype().map_or("", |s| { s.to_str().unwrap_or("") }));
69    }
70}
More examples
Hide additional examples
examples/list_devices.rs (line 22)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn driver(&self) -> Option<&OsStr>

Returns the name of the kernel driver attached to the device.

Examples found in repository?
examples/list_devices.rs (line 23)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn property_value<T: AsRef<OsStr>>(&self, property: T) -> Option<&OsStr>

Retrieves the value of a device property.

Source

pub fn attribute_value<T: AsRef<OsStr>>(&self, attribute: T) -> Option<&OsStr>

Retrieves the value of a device attribute.

Source

pub fn set_attribute_value<T: AsRef<OsStr>, U: AsRef<OsStr>>( &mut self, attribute: T, value: U, ) -> Result<()>

Sets the value of a device attribute.

Source

pub fn properties(&self) -> Properties<'_>

Returns an iterator over the device’s properties.

§Example

This example prints out all of a device’s properties:

for property in device.properties() {
    println!("{:?} = {:?}", property.name(), property.value());
}
Examples found in repository?
examples/list_devices.rs (line 34)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}
Source

pub fn attributes(&self) -> Attributes<'_>

Returns an iterator over the device’s attributes.

§Example

This example prints out all of a device’s attributes:

for attribute in device.attributes() {
    println!("{:?} = {:?}", attribute.name(), attribute.value());
}
Examples found in repository?
examples/list_devices.rs (line 39)
10fn list_devices(context: &libudev::Context) -> io::Result<()> {
11    let mut enumerator = try!(libudev::Enumerator::new(&context));
12
13    for device in try!(enumerator.scan_devices()) {
14        println!("");
15        println!("initialized: {:?}", device.is_initialized());
16        println!("     devnum: {:?}", device.devnum());
17        println!("    syspath: {:?}", device.syspath());
18        println!("    devpath: {:?}", device.devpath());
19        println!("  subsystem: {:?}", device.subsystem());
20        println!("    sysname: {:?}", device.sysname());
21        println!("     sysnum: {:?}", device.sysnum());
22        println!("    devtype: {:?}", device.devtype());
23        println!("     driver: {:?}", device.driver());
24        println!("    devnode: {:?}", device.devnode());
25
26        if let Some(parent) = device.parent() {
27            println!("     parent: {:?}", parent.syspath());
28        }
29        else {
30            println!("     parent: None");
31        }
32
33        println!("  [properties]");
34        for property in device.properties() {
35            println!("    - {:?} {:?}", property.name(), property.value());
36        }
37
38        println!("  [attributes]");
39        for attribute in device.attributes() {
40            println!("    - {:?} {:?}", attribute.name(), attribute.value());
41        }
42    }
43
44    Ok(())
45}

Trait Implementations§

Source§

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Device

§

impl RefUnwindSafe for Device

§

impl !Send for Device

§

impl !Sync for Device

§

impl Unpin for Device

§

impl UnwindSafe for Device

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.