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

Implement AsyncWrite for the generic Cursor<T: AsMut<[u8]>> #1109

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

Nemo157
Copy link
Member

@Nemo157 Nemo157 commented Jul 21, 2018

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.

(This PR is based off #1108 in order to have some "real" code changes to evaluate the ergonomics on)

}
impl<T: AsMut<[u8]>> AsyncWrite for StdIo::Cursor<T> {
fn poll_write(&mut self, _: &mut task::Context, buf: &[u8])
-> Poll<Result<usize>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.
@MajorBreakfast
Copy link
Contributor

I would like that the others look at this as well. I'm not familiar enough with the i/o stuff.

@cramertj
Copy link
Member

This looks fine to me!

@cramertj cramertj merged commit d6b7b15 into rust-lang:master Jul 23, 2018
@Nemo157 Nemo157 deleted the asyncwrite-cursor-asmut branch July 23, 2018 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants