[PATCH v2 1/5] rust: pin-init: examples: use `Wrapper::pin_init` instead of manual reimplementation

From: Gary Guo

Date: Wed Jul 29 2026 - 12:24:26 EST


`UnsafeCell` is able to obtain the extension trait via `Wrapper`.

Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
---
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