Skip to content

Commit 11551d3

Browse files
author
Danilo Krummrich
committed
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: Alice Ryhl <[email protected]> Suggested-by: Alice Ryhl <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 0cabcca commit 11551d3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rust/kernel/types.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ impl<T> Opaque<T> {
326326
}
327327
}
328328

329+
/// Create an opaque pin-initializer from the given pin-initializer.
330+
pub fn pin_init(slot: impl PinInit<T>) -> impl PinInit<Self> {
331+
Self::ffi_init(|ptr: *mut T| {
332+
// SAFETY:
333+
// - `ptr` is a valid pointer to uninitialized memory,
334+
// - `slot` is not accessed on error; the call is infallible,
335+
// - `slot` is pinned in memory.
336+
let _ = unsafe { init::PinInit::<T>::__pinned_init(slot, ptr) };
337+
})
338+
}
339+
329340
/// Creates a pin-initializer from the given initializer closure.
330341
///
331342
/// The returned initializer calls the given closure with the pointer to the inner `T` of this

0 commit comments

Comments
 (0)