Macro kernel::container_of[][src]

macro_rules! container_of {
    ($ptr:expr, $type:ty, $($f:tt)*) => { ... };
Expand description

Produces a pointer to an object from a pointer to one of its fields.


Callers must ensure that the pointer to the field is in fact a pointer to the specified field, as opposed to a pointer to another object of the same type.


struct Test {
    a: u64,
    b: u32,

fn test() {
    let test = Test { a: 10, b: 20 };
    let b_ptr = &test.b;
    let test_alias = unsafe { container_of!(b_ptr, Test, b) };
    // This prints `true`.
    pr_info!("{}\n", core::ptr::eq(&test, test_alias));