Commit 3ff6e785 authored by Benno Lossin's avatar Benno Lossin Committed by Miguel Ojeda

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: default avatarBenno Lossin <benno.lossin@proton.me>
Reviewed-by: default avatarGary Guo <gary@garyguo.net>
Reviewed-by: default avatarAndreas Hindborg <a.hindborg@samsung.com>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20230408122429.1103522-6-y86-dev@protonmail.comSigned-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent d6dbca35
...@@ -238,6 +238,14 @@ pub const fn uninit() -> Self { ...@@ -238,6 +238,14 @@ pub const fn uninit() -> Self {
pub fn get(&self) -> *mut T { pub fn get(&self) -> *mut T {
UnsafeCell::raw_get(self.0.as_ptr()) 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`. /// A sum type that always holds either a value of type `L` or `R`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment