How do I take a `Pin<Box<T>>` from a struct in a method that consumes that struct?
20:17 23 Nov 2025

Let's say I've got a struct that contains a pinned pointer to a boxed T:

struct S {
    t: Pin>,
}

How do I implement the following function without needing to add an otherwise-unnecessary Option layer? Unsafe code is fine.

impl S {
    /// Release the handle to the `T` object, consuming the struct.
    pub fn into_t(self) -> Pin> {
        todo!();
    }
}

The basic challenge is that Pin> has no "missing" representation so can't directly be taken. I can think of ways to do it with ManuallyDrop and type punning, but I'm not 100% sure that the type punning is guaranteed to be okay. I'm looking for either an API that does this directly, or citations for memory layout that say it's okay to do whatever tricks the answer contains.

rust unsafe