Navigation Menu

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 write_all_buf to AsyncWriteExt #3737

Merged
merged 6 commits into from May 1, 2021
Merged

Conversation

rcoh
Copy link
Contributor

@rcoh rcoh commented Apr 30, 2021

This commit adds write_buf_all to AsyncWriteExt. This enables
users to write an entire Buf to a writer without needing to manually
loop through each chunk of the Buf manually.

Motivation

With write_buf, users still need to loop through the individual chunks of the buffer. This both more verbose and has a misuse potential where a user thinks that the entire buf will be written.

Solution

Add write_all_buf which provides a 1-call API to write an entire impl Buf to AsyncWrite

This commit adds write_buf_all to AsyncWriteExt. This enables
users to write an entire `Buf` to a writer without needing to manually
loop through each chunk of the `Buf` manually.
@rcoh rcoh changed the title io: Add write_buf_all to AsyncWriteExt io: Add write_all_buf to AsyncWriteExt Apr 30, 2021
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Apr 30, 2021
Comment on lines 279 to 281
fn write_all_buf<'a, B>(&'a mut self, src: &'a mut B) -> WriteAllBuf<'a, Self, B> where Self: Sized + Unpin, B: Buf {
write_all_buf(self, src)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run this through rustfmt.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using rustfmt from the commandline will not fix this due to the macro around the trait. You will need to paste it elsewhere. Correctly rustfmtd code does not have the where clause like that.

$($fut)*::new(self, n)
}
)*
(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formatting only change. This is a result of getting rustfmt to actually run on this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the entire macro got indented four spaces too far. Can you undo this one?

///
/// # Examples
///
/// [`File`] implements `Read` and [`Cursor<&[u8]>`] implements [`Buf`]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the cursor link here is broken.

Copy link
Contributor Author

@rcoh rcoh May 1, 2021

Choose a reason for hiding this comment

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

good catch. It was broken for write_buf as well (& it was just wrong, I think? I believe it meant to say file implements AsyncWrite`).

I fixed both.

@rcoh
Copy link
Contributor Author

rcoh commented May 1, 2021

docs rendered:
Screen Shot 2021-05-01 at 11 20 20 AM

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