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

feature: Allow DST ReadHalf and WriteHalf Type parameters #6186

Closed
wants to merge 3 commits into from
Closed

feature: Allow DST ReadHalf and WriteHalf Type parameters #6186

wants to merge 3 commits into from

Conversation

C0D3-M4513R
Copy link

@C0D3-M4513R C0D3-M4513R commented Dec 1, 2023

Motivation

I want to allow wrapping a AsyncRead+AsyncWrite type with various wrappers, that can modify the stream, whilst still being able to use ReadHalf and WriteHalf. The easiest way to achieve this is by just using dyn AsyncRead+AsyncWrite.

Since ReadHalf and WriteHalf already use an Arc internally, I thought that this might be a good contribution.

Note: this toppic is kind of adjacent to #6169

Solution

I made the Inner struct DST, by moving the stream field to the end of that struct, because Rust only allows DST's to be at the end of a Struct.

Then I modified ReadHalf and WriteHalf to also allow unsized type Parameters.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Dec 3, 2023
@Darksonn
Copy link
Contributor

Darksonn commented Dec 3, 2023

This doesn't introduce any way to construct a non-sized ReadHalf/WriteHalf?

@C0D3-M4513R
Copy link
Author

Yeah, that is my oversight.
Actually constructing the ReadHalf/WriteHalf might prove challenging, as that would require passing in an unsized function argument.

@C0D3-M4513R C0D3-M4513R marked this pull request as draft December 3, 2023 12:22
@C0D3-M4513R C0D3-M4513R marked this pull request as ready for review December 3, 2023 12:37
///
/// To restore this read/write object from its `ReadHalf` and
/// `WriteHalf` use [`unsplit`](ReadHalf::unsplit()).
pub struct StreamSpliterHelper<T:?Sized>{
Copy link
Author

Choose a reason for hiding this comment

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

The name of that struct might need improving.
Any suggestions?

@C0D3-M4513R
Copy link
Author

Seems like there is no good way to create an unsized ReadHalf/WriteHalf...
Guess I just have to use Boxing

@C0D3-M4513R C0D3-M4513R closed this Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-io Module: tokio/io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants