pub struct Device { /* private fields */ }
Expand description
A structure that provides access to sysfs/kernel devices.
Implementations§
Source§impl Device
impl Device
Sourcepub fn from_syspath(context: &Context, syspath: &Path) -> Result<Self>
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
.
Sourcepub fn is_initialized(&self) -> bool
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?
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}
Sourcepub fn devnum(&self) -> Option<dev_t>
pub fn devnum(&self) -> Option<dev_t>
Gets the device’s major/minor number.
Examples found in repository?
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}
Sourcepub fn syspath(&self) -> Option<&Path>
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?
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
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}
Sourcepub fn devpath(&self) -> Option<&OsStr>
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?
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}
Sourcepub fn devnode(&self) -> Option<&Path>
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?
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}
Sourcepub fn parent(&self) -> Option<Device>
pub fn parent(&self) -> Option<Device>
Returns the parent of the device.
Examples found in repository?
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}
Sourcepub fn subsystem(&self) -> Option<&OsStr>
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?
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
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}
Sourcepub fn sysname(&self) -> Option<&OsStr>
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?
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
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}
Sourcepub fn sysnum(&self) -> Option<usize>
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?
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}
Sourcepub fn devtype(&self) -> Option<&OsStr>
pub fn devtype(&self) -> Option<&OsStr>
Returns the devtype name of the device.
Examples found in repository?
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
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}
Sourcepub fn driver(&self) -> Option<&OsStr>
pub fn driver(&self) -> Option<&OsStr>
Returns the name of the kernel driver attached to the device.
Examples found in repository?
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}
Sourcepub fn property_value<T: AsRef<OsStr>>(&self, property: T) -> Option<&OsStr>
pub fn property_value<T: AsRef<OsStr>>(&self, property: T) -> Option<&OsStr>
Retrieves the value of a device property.
Sourcepub fn attribute_value<T: AsRef<OsStr>>(&self, attribute: T) -> Option<&OsStr>
pub fn attribute_value<T: AsRef<OsStr>>(&self, attribute: T) -> Option<&OsStr>
Retrieves the value of a device attribute.
Sourcepub fn set_attribute_value<T: AsRef<OsStr>, U: AsRef<OsStr>>(
&mut self,
attribute: T,
value: U,
) -> Result<()>
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.
Sourcepub fn properties(&self) -> Properties<'_> ⓘ
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?
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}
Sourcepub fn attributes(&self) -> Attributes<'_> ⓘ
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?
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}