mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
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 <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230408122429.1103522-6-y86-dev@protonmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
d6dbca3592
commit
3ff6e785ad
1 changed files with 8 additions and 0 deletions
|
@ -238,6 +238,14 @@ impl<T> Opaque<T> {
|
||||||
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`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue