File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,25 @@ impl<Ctx: DeviceContext> Device<Ctx> {
6767 self . 0 . get ( )
6868 }
6969
70+ /// Returns a reference to the parent device, if any.
71+ #[ expect( unused) ]
72+ pub ( crate ) fn parent ( & self ) -> Option < & Self > {
73+ // SAFETY:
74+ // - By the type invariant `self.as_raw()` is always valid.
75+ // - The parent device is only ever set at device creation.
76+ let parent = unsafe { ( * self . as_raw ( ) ) . parent } ;
77+
78+ if parent. is_null ( ) {
79+ None
80+ } else {
81+ // SAFETY:
82+ // - Since `parent` is not NULL, it must be a valid pointer to a `struct device`.
83+ // - `parent` is valid for the lifetime of `self`, since a `struct device` holds a
84+ // reference count of its parent.
85+ Some ( unsafe { Self :: as_ref ( parent) } )
86+ }
87+ }
88+
7089 /// Convert a raw C `struct device` pointer to a `&'a Device`.
7190 ///
7291 /// # Safety
You can’t perform that action at this time.
0 commit comments