[go: nahoru, domu]

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

Need a story about implementing async-read, async-write #181

Open
1 of 4 tasks
nikomatsakis opened this issue Apr 29, 2021 · 5 comments
Open
1 of 4 tasks

Need a story about implementing async-read, async-write #181

nikomatsakis opened this issue Apr 29, 2021 · 5 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas

Comments

@nikomatsakis
Copy link
Contributor

Brief summary

I've heard that it's common want to wrap async-read or async-write, particularly with folks come from Java where this kind of pattern is very complicated. But it's hard to do because Pin (similar perhaps to "Alan Hates Writing a Stream")

Optional details

  • (Optional) Which character(s) would be the best fit and why?
    • Alan: the experienced "GC'd language" developer, new to Rust -- maybe?
    • Grace: the systems programming expert, new to Rust
    • Niklaus: new programmer from an unconventional background
    • Barbara: the experienced Rust developer
  • (Optional) Which project(s) would be the best fit and why?
    • List some projects here.
  • (Optional) What are the key points or morals to emphasize?
    • Write some morals here.
@nikomatsakis nikomatsakis added good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas labels Apr 29, 2021
@rylev
Copy link
Member
rylev commented Apr 30, 2021

FYI: We had a writing session on this today, and we should be having the first (of hopefully 2-3) status-quo stories coming for this soon.

@nikomatsakis
Copy link
Contributor Author

ooh, nice!

@eminence
Copy link
Contributor
eminence commented May 5, 2021

An interesting aspect to this story could be: does Alan write an impl for tokio's AsyncWrite or future's AsyncWrite ?

@jbr
Copy link
jbr commented May 5, 2021

I'm not sure if "wrap" in the description is the same as this, but I keep wanting it to be easier to delegate AsyncRead and/or AsyncWrite to an inner type, either through a pin projection or by unpinning. The vast majority of AsyncRead/Write implementations I write are just boilerplate delegation. It would be cool if that could look like a derive macro, but that would also have to be aware of pin projection

An example in case it's not clear:

#[derive(AsyncRead, AsyncWrite)]
struct SomeType {
    #[async_read]
    #[async_write]
    unpinnable_inner: SomethingReadAndWrite
}

// would result in 👇 
impl AsyncRead for SomeType {
    fn poll_read(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<Result<usize>> {
        Pin::new(&mut self.unpinnable_inner).poll_read(cx, buf)
    }
}

impl AsyncWrite for SomeType {
    fn poll_write(
        mut self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize>> {
        Pin::new(&mut self.unpinnable_inner).poll_write(cx, buf)
    }

    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
        Pin::new(&mut self.unpinnable_inner).poll_flush(cx)
    }

    fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
        Pin::new(&mut self.unpinnable_inner).poll_close(cx)
    }
}

and the !Unpin equivalent is that but with self.project().non_unpin_inner.poll_whatever.

This might be identical to what the issue is about, I'm not sure

@nikomatsakis
Copy link
Contributor Author

Yes, that is what this issue is about. The difficulty of writing wrappers that work with Poll, the need to use pin-project, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas
Projects
None yet
Development

No branches or pull requests

4 participants