Device

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(syspath: &Path) -> Result<Device, Error>

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 from_syspath_with_context( udev: Udev, syspath: &Path, ) -> Result<Device, Error>

Creates a device for a given syspath, using an existing Udev instance rather than creating one automatically.

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.

Source

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

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.

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<Device>

Returns the parent of the device.

Source

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

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

Source

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

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.

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.

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.

Source

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

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

Source

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

Retreives the value of a device property.

Source

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

Retreives the value of a device attribute.

Source

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

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

Trait Implementations§

Source§

impl AsRawWithContext<udev_device> for Device

Source§

fn as_raw(&self) -> *mut udev_device

Get a reference of the underlying struct. Read more
Source§

fn udev(&self) -> &Udev

The udev context with which this struct was created. This must live at least as long as the struct itself or undefined behavior will result.
Source§

fn into_raw_with_context(self) -> (*mut udev, *mut udev_device)

Convert the object into the raw udev pointer and the underlying pointer for this object. Read more
Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl FromRawWithContext<udev_device> for Device

Source§

unsafe fn from_raw_with_context(udev: *mut udev, t: *mut udev_device) -> Device

Create an object from a given raw pointer and udev context pointer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.