kernel::device_id

Trait RawDeviceIdIndex

Source
pub unsafe trait RawDeviceIdIndex: RawDeviceId {
    const DRIVER_DATA_OFFSET: usize;

    // Provided methods
    unsafe fn info_unchecked<U>(&self) -> &'static U { ... }
    unsafe fn info_unchecked_opt<U>(&self) -> Option<&'static U> { ... }
}
Expand description

Extension trait for RawDeviceId for devices that embed an index or context value.

This is typically used when the device ID struct includes a field like driver_data that is used to store a pointer-sized value (e.g., an index or context pointer).

§Safety

Implementers must ensure that DRIVER_DATA_OFFSET is the correct offset (in bytes) to the context/data field (e.g., the driver_data field) within the raw device ID structure. This field must be correctly sized to hold a usize.

Ideally, the data should be added during Self to RawType conversion, but there’s currently no way to do it when using traits in const.

Required Associated Constants§

Source

const DRIVER_DATA_OFFSET: usize

The offset (in bytes) to the context/data field in the raw device ID.

Provided Methods§

Source

unsafe fn info_unchecked<U>(&self) -> &'static U

Obtain the data pointer stored inside the device ID.

§Safety

&Self must be stored inside a IdArray<Self, U>.

Source

unsafe fn info_unchecked_opt<U>(&self) -> Option<&'static U>

Obtain the data pointer stored inside the device ID.

§Safety

&Self must be stored inside a IdArray<Self, U>, or has NULL (or 0) as driver data.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl RawDeviceIdIndex for kernel::acpi::DeviceId

Source§

impl RawDeviceIdIndex for kernel::auxiliary::DeviceId

Source§

impl RawDeviceIdIndex for kernel::i2c::DeviceId

Source§

impl RawDeviceIdIndex for kernel::of::DeviceId

Source§

impl RawDeviceIdIndex for kernel::pci::DeviceId

Source§

impl RawDeviceIdIndex for kernel::usb::DeviceId