rust: types: rename Opaque::raw_get to cast_into
In the previous patch we added Opaque::cast_from() that performs the opposite operation to Opaque::raw_get(). For consistency with this naming, rename raw_get() to cast_from(). There are a few other options such as calling cast_from() something closer to raw_get() rather than renaming this method. However, I could not find a great naming scheme that works with raw_get(). The previous version of this patch used from_raw(), but functions of that name typically have a different signature, so that's not a great option. Suggested-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Benno Lossin <lossin@kernel.org> Acked-by: Andreas Hindborg <a.hindborg@kernel.org> Acked-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Danilo Krummrich <dakr@kernel.org> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20250624-opaque-from-raw-v2-2-e4da40bdc59c@google.com [ Removed `HrTimer::raw_get` change. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
@@ -377,7 +377,7 @@ impl<T> Opaque<T> {
|
||||
// initialize the `T`.
|
||||
unsafe {
|
||||
pin_init::pin_init_from_closure::<_, ::core::convert::Infallible>(move |slot| {
|
||||
init_func(Self::raw_get(slot));
|
||||
init_func(Self::cast_into(slot));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -397,7 +397,7 @@ impl<T> Opaque<T> {
|
||||
// SAFETY: We contain a `MaybeUninit`, so it is OK for the `init_func` to not fully
|
||||
// initialize the `T`.
|
||||
unsafe {
|
||||
pin_init::pin_init_from_closure::<_, E>(move |slot| init_func(Self::raw_get(slot)))
|
||||
pin_init::pin_init_from_closure::<_, E>(move |slot| init_func(Self::cast_into(slot)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,11 +410,11 @@ impl<T> Opaque<T> {
|
||||
///
|
||||
/// This function is useful to get access to the value without creating intermediate
|
||||
/// references.
|
||||
pub const fn raw_get(this: *const Self) -> *mut T {
|
||||
pub const fn cast_into(this: *const Self) -> *mut T {
|
||||
UnsafeCell::raw_get(this.cast::<UnsafeCell<MaybeUninit<T>>>()).cast::<T>()
|
||||
}
|
||||
|
||||
/// The opposite operation of [`Opaque::raw_get`].
|
||||
/// The opposite operation of [`Opaque::cast_into`].
|
||||
pub const fn cast_from(this: *const T) -> *const Self {
|
||||
this.cast()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user