Skip to content

Commit 3ff6e78

Browse files
y86-devojeda
authored andcommitted
rust: types: add Opaque::raw_get
This function mirrors `UnsafeCell::raw_get`. It avoids creating a reference and allows solely using raw pointers. The `pin-init` API will be using this, since uninitialized memory requires raw pointers. Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Gary Guo <[email protected]> Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent d6dbca3 commit 3ff6e78

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

rust/kernel/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ impl<T> Opaque<T> {
238238
pub fn get(&self) -> *mut T {
239239
UnsafeCell::raw_get(self.0.as_ptr())
240240
}
241+
242+
/// Gets the value behind `this`.
243+
///
244+
/// This function is useful to get access to the value without creating intermediate
245+
/// references.
246+
pub const fn raw_get(this: *const Self) -> *mut T {
247+
UnsafeCell::raw_get(this.cast::<UnsafeCell<T>>())
248+
}
241249
}
242250

243251
/// A sum type that always holds either a value of type `L` or `R`.

0 commit comments

Comments
 (0)