Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to guarantee the type is !Unpin #108

Closed
taiki-e opened this issue Sep 25, 2019 · 3 comments · Fixed by #219
Closed

Provide a way to guarantee the type is !Unpin #108

taiki-e opened this issue Sep 25, 2019 · 3 comments · Fixed by #219
Assignees
Labels
A-unpin Area: Unpin and UnsafeUnpin C-enhancement Category: A new feature or an improvement for an existing one

Comments

@taiki-e
Copy link
Owner

taiki-e commented Sep 25, 2019

UPDATE: see #108 (comment).

As mentioned in #102, it seems difficult to guarantee this with stable rust at this time.

However, I think it would be preferable if an option like #[pin_project(!Unpin)] could be provided in the future.

Some ways have been mentioned in #102, but it needs to work correctly for generics and conditional implementations in order to use with pin-project.

@taiki-e taiki-e added C-enhancement Category: A new feature or an improvement for an existing one A-unpin Area: Unpin and UnsafeUnpin labels Sep 25, 2019
@taiki-e taiki-e changed the title Provides a way to guarantee the type is !Unpin Provide a way to guarantee the type is !Unpin Sep 25, 2019
bors bot added a commit that referenced this issue Sep 26, 2019
111: Add a dummy lifetime to UnpinStruct r=taiki-e a=taiki-e

Basically the same as #107.

This fixes #102 completely.

cc #108


Co-authored-by: Taiki Endo <te316e89@gmail.com>
bors bot added a commit that referenced this issue Sep 26, 2019
111: Add a dummy lifetime to UnpinStruct r=taiki-e a=taiki-e

Basically the same as #107.

This fixes #102 completely.

cc #108


Co-authored-by: Taiki Endo <te316e89@gmail.com>
@taiki-e
Copy link
Owner Author

taiki-e commented Sep 26, 2019

We can now support #102 without UnsafeUnpin, so I don't think we need negative implementation support.

(It is recommended to always use the default #[pin_project].)

@taiki-e taiki-e closed this as completed Sep 26, 2019
@taiki-e
Copy link
Owner Author

taiki-e commented Nov 15, 2019

FYI: this can be implemented by

pub struct Wrapper <'a, T> (PhantomData<&'a ()>, PhantomData<T>);
impl<T> Unpin for Wrapper<'_, T> where T: Unpin {}
impl Unpin for Foo where Wrapper<'_, PhantomPinned>: Unpin {}

@taiki-e
Copy link
Owner Author

taiki-e commented May 8, 2020

This is equivalent to:

#[pin_project]
struct S {
    #[pin]
    _pin: PhantomPinned,
}

And I know that some people are using this: https://github.com/sfackler/rust-postgres/blob/1c843c8b22b37a279172da2ce4ba053506f57802/tokio-postgres/src/copy_out.rs#L46

@taiki-e taiki-e reopened this May 8, 2020
@taiki-e taiki-e self-assigned this May 8, 2020
@bors bors bot closed this as completed in 7824db7 May 9, 2020
@bors bors bot closed this as completed in #219 May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-unpin Area: Unpin and UnsafeUnpin C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant