diff options
author | Benno Lossin <[email protected]> | 2023-04-08 12:25:39 +0000 |
---|---|---|
committer | Miguel Ojeda <[email protected]> | 2023-04-12 18:41:05 +0200 |
commit | 3ff6e785ad99893f1d502156d23560efd30fec4d (patch) | |
tree | 43f1469f5ea3e1cc17096d757b272cd5313b72b1 /rust/kernel | |
parent | d6dbca3592209d29c10e171224c34803805e88ca (diff) |
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]>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/types.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 9d0fdbc55843..ff2b2fac951d 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -238,6 +238,14 @@ impl<T> Opaque<T> { pub fn get(&self) -> *mut T { UnsafeCell::raw_get(self.0.as_ptr()) } + + /// Gets the value behind `this`. + /// + /// This function is useful to get access to the value without creating intermediate + /// references. + pub const fn raw_get(this: *const Self) -> *mut T { + UnsafeCell::raw_get(this.cast::<UnsafeCell<T>>()) + } } /// A sum type that always holds either a value of type `L` or `R`. |