[][src]Macro intrusive_collections::container_of

macro_rules! container_of {
    ($ptr:expr, $container:path, $field:ident) => { ... };

Unsafe macro to get a raw pointer to an outer object from a pointer to one of its fields.


use intrusive_collections::container_of;

struct S { x: u32, y: u32 };
let container = S { x: 1, y: 2 };
let field = &container.x;
let container2: *const S = unsafe { container_of!(field, S, x) };
assert_eq!(&container as *const S, container2);


This is unsafe because it assumes that the given expression is a valid pointer to the specified field of some container type.