Skip to content

core/muxing: Have functions on StreamMuxer take Pin<&mut Self>#2765

Merged
thomaseizinger merged 12 commits intomasterfrom
feature/pin-mut-self-muxer
Aug 3, 2022
Merged

core/muxing: Have functions on StreamMuxer take Pin<&mut Self>#2765
thomaseizinger merged 12 commits intomasterfrom
feature/pin-mut-self-muxer

Conversation

@thomaseizinger
Copy link
Copy Markdown
Contributor

@thomaseizinger thomaseizinger commented Jul 20, 2022

Description

This is the idiomatic way of doing poll interface in Rust.

Links to any relevant issues

#2722
Depends on #2763.
Depends on #2764.
Depends on #2775.
Depends on #2776.

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

This is the idiomatic way of defining `poll`-based interfaces in
Rust despite introducing a bit of inconvenience.

To work around this inconvenience, we also introduce a `StreamMuxerExt`
trait allows for better integration with async-await style code and
adds a `_unpin` variant to for each `poll` function of the `StreamMuxer`.
Now that the `StreamMuxer` interface has `Pin<&mut Self>` receivers,
we can drop the `Mutex` from the yamux implementation.
@thomaseizinger thomaseizinger changed the title Introduce StreamMuxerExt trait core/muxing: Have functions on StreamMuxer take Pin<&mut Self> Jul 20, 2022
thomaseizinger and others added 4 commits July 23, 2022 19:46
Co-authored-by: Elena Frank <[email protected]>
The muxer is useless after polling `poll_close` to completion, thus
we can consume `self` in the extension trait method which allows us
to use the function within `libp2p_swarm::Connection`.
Copy link
Copy Markdown
Member

@mxinden mxinden 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 the patch using Pin.

@thomaseizinger thomaseizinger marked this pull request as ready for review July 31, 2022 15:25
@thomaseizinger
Copy link
Copy Markdown
Contributor Author

@elenaf9 @mxinden This is ready for another review.

I believe this is useful despite the on-going discussion on the overall design because we will be using Pin anyway for poll function.

@mxinden mxinden mentioned this pull request Aug 3, 2022
4 tasks
Copy link
Copy Markdown
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Wonderful to see this happening! 🙏

@mxinden
Copy link
Copy Markdown
Member

mxinden commented Aug 3, 2022

@elenaf9 any objections to me merging here with the discussion on #2722 (comment) in mind?

I think we want to take Pin<&mut Self> no matter whether we go with 3 poll_ methods (poll_inbound, poll_outbound, poll_close) or one (poll).

Copy link
Copy Markdown
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@thomaseizinger thomaseizinger merged commit 028dece into master Aug 3, 2022
@thomaseizinger thomaseizinger deleted the feature/pin-mut-self-muxer branch August 3, 2022 13:12
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.

4 participants