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

io: add copy_buf #2884

Merged
merged 4 commits into from
Oct 19, 2020
Merged

io: add copy_buf #2884

merged 4 commits into from
Oct 19, 2020

Conversation

zaharidichev
Copy link
Contributor

Motivation

Add copy_buf function like the one from futures, but with tokio's async io traits.

Solution

Add io::copy_buf function.
Fix #2797

Signed-off-by: Zahari Dichev zaharidichev@gmail.com

Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-io Module: tokio/io labels Sep 25, 2020
tokio/src/io/util/copy_buf.rs Outdated Show resolved Hide resolved
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct CopyBuf<'a, R: ?Sized, W: ?Sized> {
reader: &'a mut R,
Copy link
Member

Choose a reason for hiding this comment

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

FYI: futures's copy_buf takes the reader by value to allow !Unpin reader. (This is only done in the reader as only the reader is exhausted by this operation.)

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, taking it by reference is consistent with Tokio's copy. In either case, !Unpin readers can still be used here if combined with tokio::pin!.

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, taking it by reference is consistent with Tokio's copy.

Yeah, if copy_buf takes the reader by value, copy also needs to take the reader by value for consistency.

@carllerche
Copy link
Member

This is fine w/ me, but based on #2428, it looks like AsyncBufRead is going to be moved to tokio-util. Maybe we should wait for that to happen before merging this PR? Thoughts @seanmonstar

@Darksonn
Copy link
Contributor

Note that the AsyncBufRead thing was postponed for now.

@zaharidichev zaharidichev requested a review from Darksonn October 15, 2020 11:45
@Darksonn Darksonn merged commit 423ecc1 into tokio-rs:master Oct 19, 2020
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 C-enhancement Category: A PR with an enhancement or bugfix. M-io Module: tokio/io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add copy_buf
4 participants