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

async equivalent of std::io::LineWriter? #2131

Closed
anp opened this issue Apr 20, 2020 · 4 comments · Fixed by #2477
Closed

async equivalent of std::io::LineWriter? #2131

anp opened this issue Apr 20, 2020 · 4 comments · Fixed by #2477

Comments

@anp
Copy link
Member

anp commented Apr 20, 2020

AsyncBufReadExt::lines exists but there's no async+line-buffered generic writer available AFAICT.

In scope?

@taiki-e
Copy link
Member

taiki-e commented Jan 14, 2021

I would accept a PR to add this. (I've previously tried this a bit, but I remember finding it difficult.)

@FelipeLema
Copy link
Contributor

FelipeLema commented Aug 18, 2021

hi, there

I was trying to address this by adapting std::io::LineWriter and its LineWriterShime sidekick, but I'm having trouble handling Pins and references.

Particularly, I'm not understanding how a WIP-futures_util::io::LineWriterShim can receive WIP-futures_util::io::LineWriter 's buffer writer.

If, instead, I try to merge LineWriterShim into LineWriter, then I have trouble with newly-added-BufWriter::write_to_buffer_unchecked()

Perhaps I should do a draft PR instead 🤔

@FelipeLema
Copy link
Contributor

FelipeLema commented Aug 19, 2021

let me re-phrase the above

I'm not certain of how to "balance out" refs and pinning.

For doing behavioural stuff, all is present in std::io::LineWriter, but it's all doing mutable refs (specifically, writing directly to BufWriter's internal buffer). For doing async stuff, all is done with Pin::new, #[pin] and such.

Both pin-ey and ref-ey code don't play well with each other.

For example, how would I write a poll_write that may write to a BufWriter's internal buffer? Right now, rustc is complaining that I cannot declare flush_if_completed_line() to receive self as Pin<&mut Self or as &mut Self (not with the same error, of course)

@taiki-e
Copy link
Member

taiki-e commented Aug 21, 2021

For example, how would I write a poll_write that may write to a BufWriter's internal buffer? Right now, rustc is complaining that I cannot declare flush_if_completed_line() to receive self as Pin<&mut Self or as &mut Self (not with the same error, of course)

In #2477, you need to always use Pin<&mut Self> instead of &mut self.

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

Successfully merging a pull request may close this issue.

3 participants