-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
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.
tokio/src/io/util/async_write_ext.rs
Outdated
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
tokio/src/io/util/async_write_ext.rs
Outdated
$($fut)*::new(self, n) | ||
} | ||
)* | ||
( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
tokio/src/io/util/async_write_ext.rs
Outdated
/// | ||
/// # Examples | ||
/// | ||
/// [`File`] implements `Read` and [`Cursor<&[u8]>`] implements [`Buf`]: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This commit adds write_buf_all to AsyncWriteExt. This enables
users to write an entire
Buf
to a writer without needing to manuallyloop 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 entireimpl Buf
toAsyncWrite