Struct udev::Event

source ·
pub struct Event { /* private fields */ }
Expand description

An event that indicates a change in device state.

Implementations§

source§

impl Event

source

pub fn event_type(&self) -> EventType

Returns the EventType corresponding to this event.

Examples found in repository?
examples/monitor.rs (line 161)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
source

pub fn sequence_number(&self) -> u64

Returns the event’s sequence number.

Examples found in repository?
examples/monitor.rs (line 160)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
source

pub fn device(&self) -> Device

Returns the device associated with this event.

Methods from Deref<Target = Device>§

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.

source

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

Gets the device’s major/minor number.

source

pub fn syspath(&self) -> &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 162)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
source

pub fn devpath(&self) -> &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.

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.

source

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

Returns the parent of the device.

source

pub fn parent_with_subsystem<T: AsRef<OsStr>>( &self, subsystem: T ) -> Result<Option<Self>>

Returns the parent of the device with the matching subsystem and devtype if any.

source

pub fn parent_with_subsystem_devtype<T: AsRef<OsStr>, U: AsRef<OsStr>>( &self, subsystem: T, devtype: U ) -> Result<Option<Self>>

Returns the parent of the device with the matching subsystem and devtype if any.

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 164)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
source

pub fn sysname(&self) -> &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 166)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
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.

source

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

Returns the devtype name of the device (if any), for example “disk”.

Examples found in repository?
examples/monitor.rs (line 167)
157
158
159
160
161
162
163
164
165
166
167
168
169
fn print_event(event: udev::Event) {
    println!(
        "{}: {} {} (subsystem={}, sysname={}, devtype={})",
        event.sequence_number(),
        event.event_type(),
        event.syspath().to_str().unwrap_or("---"),
        event
            .subsystem()
            .map_or("", |s| { s.to_str().unwrap_or("") }),
        event.sysname().to_str().unwrap_or(""),
        event.devtype().map_or("", |s| { s.to_str().unwrap_or("") })
    );
}
source

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

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

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 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 13)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() -> io::Result<()> {
    let mut enumerator = udev::Enumerator::new()?;

    for device in enumerator.scan_devices()? {
        println!();
        println!("{:#?}", device);

        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(())
}
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 18)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() -> io::Result<()> {
    let mut enumerator = udev::Enumerator::new()?;

    for device in enumerator.scan_devices()? {
        println!();
        println!("{:#?}", device);

        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(())
}
source

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

Returns the device action for the device.

Trait Implementations§

source§

impl Debug for Event

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Event

Provides access to the device associated with the event.

§

type Target = Device

The resulting type after dereferencing.
source§

fn deref(&self) -> &Device

Dereferences the value.

Auto Trait Implementations§

§

impl RefUnwindSafe for Event

§

impl !Send for Event

§

impl !Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.