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

Don't project if you require Unpin. #90

Closed
wants to merge 2 commits into from

Conversation

najamelan
Copy link
Contributor

This is the counter proposition of #89. Since it's rather convoluted to remove the Unpin requirement on the underlying stream users can wrap in WebSocketStream and I don't know of any use cases for it, I propose to keep the Unpin and consequently remove pin-projection from tokio-tungstenite. This also sheds a dependency.

The first commit is completely self contained. Nothing outside of this file will observe any difference. I think it's good to apply it no matter what except if choosing to remove Unpin bounds everywhere as discussed in #89.

The second is a bit more complicated. It's concerned with the handshake, which takes place before there even is a WebSocketStream. There is a type Role::InternalStream, which comes from tungstenite, which uses trait bounds Read + Write and doesn't mention Unpin. The current state allowed this type to be !Unpin, although I suspect that normally this is the same underlying connection that is used for wrapping in WebSocketStream, so there probably already wasn't any way for users to pass a !Unpin type in here.

However, I haven't actually tested this assumption. If the assumption holds, I suppose this is not a breaking change. If it changes what people could pass in, it is a breaking change.

This doesn't make sense. For Unpin types, Pin does nothing, so Pin::new() is sufficient
and there is no need to project.

If it's projected, it's already pinned, so no need to call Pin::new().

Thus project and Pin::new together is always a code smell.
@najamelan
Copy link
Contributor Author

@sdroege what do you think of this solution? Would you like an equivalent PR on async-tungstenite?

@sdroege
Copy link
Contributor

sdroege commented Mar 9, 2020

I think it makes sense, yes

@najamelan
Copy link
Contributor Author

oh, and what I didn't think of before, users should still be able use !Unpin streams, they just have to pin them first, so that's not to bad. I havn't tested that, but AsyncRead is implemented for Pinned AsyncRead in any case.

Copy link
Member

@daniel-abramov daniel-abramov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this issue, @najamelan . I did not think that deep about this issue previously. Well, for me it seems that the approach suggested here (#90) would indeed be a better solution for now and additionally we get rid of the pin-project dependency "for free".

@agalakhov what do you think? #89 vs #90 ?

@najamelan
Copy link
Contributor Author

Note that async-tungstenite, which is a fork with almost identical code chose this path. I think #89 only makes sense if a real path is demonstrated which allows using !Unpin streams, which I didn't find easily.

@daniel-abramov
Copy link
Member

Thanks for tackling this issue, @najamelan . I did not think that deep about this issue previously. Well, for me it seems that the approach suggested here (#90) would indeed be a better solution for now and additionally we get rid of the pin-project dependency "for free".

@agalakhov what do you think? #89 vs #90 ?

@agalakhov , what's your opinion on that?

@agalakhov
Copy link
Member

I think #90. It looks like safer approach to me.

@Gelbpunkt Gelbpunkt mentioned this pull request Sep 22, 2021
daniel-abramov pushed a commit that referenced this pull request Oct 16, 2021
* Don't project if you require Unpin
Co-authored-by: Jens Reidel <adrian@travitia.xyz>

* remove async-await feature on futures-util

Co-authored-by: Naja Melan <najamelan@autistici.org>
@daniel-abramov
Copy link
Member

Superseded by #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants