Skip to main content

HasWork

Trait HasWork 

Source
pub unsafe trait HasWork<T, const ID: u64 = 0> {
    // Required methods
    unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work<T, ID>;
    unsafe fn work_container_of(ptr: *mut Work<T, ID>) -> *mut Self;
}
Expand description

Declares that a type contains a Work<T, ID>.

The intended way of using this trait is via the impl_has_work! macro. You can use the macro like this:

use kernel::workqueue::{impl_has_work, Work};

struct MyWorkItem {
    work_field: Work<MyWorkItem, 1>,
}

impl_has_work! {
    impl HasWork<MyWorkItem, 1> for MyWorkItem { self.work_field }
}

Note that since the Work type is annotated with an id, you can have several work_struct fields by using a different id for each one.

§Safety

The methods raw_get_work and work_container_of must return valid pointers and must be true inverses of each other; that is, they must satisfy the following invariants:

  • work_container_of(raw_get_work(ptr)) == ptr for any ptr: *mut Self.
  • raw_get_work(work_container_of(ptr)) == ptr for any ptr: *mut Work<T, ID>.

Required Methods§

Source

unsafe fn raw_get_work(ptr: *mut Self) -> *mut Work<T, ID>

Returns a pointer to the Work<T, ID> field.

§Safety

The provided pointer must point at a valid struct of type Self.

Source

unsafe fn work_container_of(ptr: *mut Work<T, ID>) -> *mut Self

Returns a pointer to the struct containing the Work<T, ID> field.

§Safety

The pointer must point at a Work<T, ID> field in a struct of type Self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, const ID: u64> HasWork<Device<T>, ID> for Device<T>
where T: Driver, T::Data: HasWork<Device<T>, ID>,