Skip to content

Pinning non-Deref pointers #54815

Open
Open
@withoutboats

Description

@withoutboats

Currently, you cannot even construct a Pin unless the pointer it wraps implements Deref. This means you cannot have a Pin<*const T>, Pin<*mut T> or Pin<NonNull<T>>. We should consider extending the API of Pin to support these constructs.

Unfortunately, I don't know if there's much this actually helps, because we have no unsafe equivalent of Deref as a trait abstraction. As a result, I think the only APIs that could apply to these pointers generically is:

  • unsafe fn new_unchecked(p: P) -> Pin<P>
  • unsafe fn into_inner(self: Pin<P>) -> P

This limits the utility of Pin on these pointers, since it basically guarantees nothing with this API.

If we had an UnsafeAsRef trait, we could support unsafe equivalents of as_ref and as_mut, allowing you to at least maintain the pinning invariant in your unsafe code. In other words, some sort of UnsafeAsRef and UnsafeAsMut traits would be necessary for this to actually be helpful. I'm not sure if those traits are worth adding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-pinArea: PinC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions