Commit 2d3bf6ff authored by Danilo Krummrich's avatar Danilo Krummrich Committed by Greg Kroah-Hartman
Browse files

rust: types: add `Opaque::pin_init`



Analogous to `Opaque::new` add `Opaque::pin_init`, which instead of a
value `T` takes a `PinInit<T>` and returns a `PinInit<Opaque<T>>`.

Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Suggested-by: default avatarAlice Ryhl <aliceryhl@google.com>
Signed-off-by: default avatarDanilo Krummrich <dakr@kernel.org>
Tested-by: default avatarDirk Behme <dirk.behme@de.bosch.com>
Tested-by: default avatarFabien Parent <fabien.parent@linaro.org>
Link: https://lore.kernel.org/r/20241219170425.12036-6-dakr@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 51158207
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -281,6 +281,17 @@ pub const fn uninit() -> Self {
        }
    }

    /// Create an opaque pin-initializer from the given pin-initializer.
    pub fn pin_init(slot: impl PinInit<T>) -> impl PinInit<Self> {
        Self::ffi_init(|ptr: *mut T| {
            // SAFETY:
            //   - `ptr` is a valid pointer to uninitialized memory,
            //   - `slot` is not accessed on error; the call is infallible,
            //   - `slot` is pinned in memory.
            let _ = unsafe { init::PinInit::<T>::__pinned_init(slot, ptr) };
        })
    }

    /// Creates a pin-initializer from the given initializer closure.
    ///
    /// The returned initializer calls the given closure with the pointer to the inner `T` of this