intrusive_collections::container_of!
[−]
[src]
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.
Examples
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 _, container2);
Safety
This is unsafe because it assumes that the given expression is a valid pointer to the specified field of some container type.