[PATCH v2 1/5] rust: pin-init: examples: use `Wrapper::pin_init` instead of manual reimplementation
Gary Guo <[email protected]> Wed, 29 Jul 2026 16:38:43 +0100
| Newsgroups | org.kernel.vger.linux-pwm,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
`UnsafeCell` is able to obtain the extension trait via `Wrapper`. Signed-off-by: Gary Guo <[email protected]> --- rust/pin-init/examples/mutex.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rust/pin-init/examples/mutex.rs b/rust/pin-init/examples/mutex.rs index 882f3e23f5dd..e8d4dbb664fe 100644 --- a/rust/pin-init/examples/mutex.rs +++ b/rust/pin-init/examples/mutex.rs @@ -79,11 +79,7 @@ pub fn new(val: impl PinInit<T>) -> impl PinInit<Self> { wait_list <- ListHead::new(), spin_lock: SpinLock::new(), locked: Cell::new(false), - data <- unsafe { - pin_init_from_closure(|slot: *mut UnsafeCell<T>| { - val.__pinned_init(slot.cast::<T>()) - }) - }, + data <- UnsafeCell::pin_init(val), }) } -- 2.54.0