pub unsafe trait RawDeviceId {
type RawType: Copy;
const DRIVER_DATA_OFFSET: usize;
// Required method
fn index(&self) -> usize;
}
Expand description
Marker trait to indicate a Rust device ID type represents a corresponding C device ID type.
This is meant to be implemented by buses/subsystems so that they can use IdTable
to
guarantee (at compile-time) zero-termination of device id tables provided by drivers.
§Safety
Implementers must ensure that:
-
Self
is layout-compatible withRawDeviceId::RawType
; i.e. it’s safe to transmute toRawDeviceId
.This requirement is needed so
IdArray::new
can convertSelf
toRawType
when building the ID table.Ideally, this should be achieved using a const function that does conversion instead of transmute; however, const trait functions relies on
const_trait_impl
unstable feature, which is broken/gone in Rust 1.73. -
DRIVER_DATA_OFFSET
is the offset of context/data field of the device ID (usually nameddriver_data
) of the device ID, the field is suitable sized to write ausize
value.Similar to the previous requirement, the data should ideally be added during
Self
toRawType
conversion, but there’s currently no way to do it when using traits in const.
Required Associated Constants§
Sourceconst DRIVER_DATA_OFFSET: usize
const DRIVER_DATA_OFFSET: usize
The offset to the context/data field.
Required Associated Types§
Required Methods§
Sourcefn index(&self) -> usize
fn index(&self) -> usize
The index stored at DRIVER_DATA_OFFSET
of the implementor of the RawDeviceId
trait.
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.