-
Notifications
You must be signed in to change notification settings - Fork 632
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
Implement AsyncWrite for the generic Cursor<T: AsMut<[u8]>> #1109
Conversation
futures-io/src/lib.rs
Outdated
} | ||
impl<T: AsMut<[u8]>> AsyncWrite for StdIo::Cursor<T> { | ||
fn poll_write(&mut self, _: &mut task::Context, buf: &[u8]) | ||
-> Poll<Result<usize>> |
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.
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 see that the whole file is full of this unusual style. Ignore this then. At some point I'll just apply rustfmt to the whole project and fix such things
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.
rustfmt
just removes some blank lines from this file, what do you see wrong here?
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.
Ah, the actual RFC doesn't allow for just splitting the return onto its own line when the args fit. I'd prefer to go with what rustfmt
does for ease of application.
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.
fn poll_write(&mut self, _: &mut task::Context, buf: &[u8])
-> Poll<Result<usize>>
{
should be
fn poll_write(
&mut self,
_: &mut task::Context,
buf: &[u8],
) -> Poll<Result<usize>> {
according to the style guide.
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.
Oh, the if_std!
macro call messes rustfmt
up since it doesn't know that the internals should be normal Rust code.
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'll fix it up anyway and rebase once #1108 is merged so this will have a decent diff.
This introduces an unfortunate point of difference between `futures::io::AsyncWrite` and `std::io::Write`, but I think the increased ergonomics around writing to statically sized in memory buffers (presumably just for test purposes) is useful. `impl<T: AsRef<[u8]>> Read for Cursor<T>` was added in rust-lang/rust#27197, I'm not sure why `impl<T: AsMut<[u8]>> Write for Cursor<T>` wasn't added at the same time; I would propose doing this change in `std` and just piggybacking off it here, but the breakage is almost certainly not worth it by this point.
c3c7bc9
to
2b675cb
Compare
I would like that the others look at this as well. I'm not familiar enough with the i/o stuff. |
This looks fine to me! |
This introduces an unfortunate point of difference between
futures::io::AsyncWrite
andstd::io::Write
, but I think the increased ergonomics around writing to statically sized in memory buffers (presumably just for test purposes) is useful.impl<T: AsRef<[u8]>> Read for Cursor<T>
was added in rust-lang/rust#27197, I'm not sure whyimpl<T: AsMut<[u8]>> Write for Cursor<T>
wasn't added at the same time; I would propose doing this change instd
and just piggybacking off it here, but the breakage is almost certainly not worth it by this point.(This PR is based off #1108 in order to have some "real" code changes to evaluate the ergonomics on)