We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c6a4a01 commit 434b8d7Copy full SHA for 434b8d7
examples/kernel_ptr.rs
@@ -50,4 +50,25 @@ where
50
}
51
52
53
+impl<'a, T: 'a> Ptr<'a, T> {
54
+ /// Turn this pointer-to-a-field into a pointer to the entire container.
55
+ ///
56
+ /// # Safety
57
58
+ /// * `self` points at a `T` that is contained as the field `F` inside of a `U`.
59
+ /// * `self` is derived from a pointer that originally pointed at the entire `U` that contains
60
+ /// this `T` as the field `F`.
61
+ pub unsafe fn container_of<U, F>(self) -> Ptr<'a, U>
62
+ where
63
+ U: 'a,
64
+ F: Field<Base = U, Type = T>,
65
+ {
66
+ let inner = unsafe { self.inner.byte_sub(F::OFFSET) };
67
+ Ptr {
68
+ inner: inner.cast(),
69
+ _phantom: PhantomData,
70
+ }
71
72
+}
73
+
74
fn main() {}
0 commit comments