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 ReadBuf::inner_mut #3443

Merged
merged 1 commit into from
Jan 20, 2021
Merged

io: add ReadBuf::inner_mut #3443

merged 1 commit into from
Jan 20, 2021

Conversation

sunshowers
Copy link
Contributor

@sunshowers sunshowers commented Jan 19, 2021

This returns the entire buffer as a &mut [MaybeUninit<u8>], which may
be useful for building abstractions on top.

Motivation

It looks like ReadBuf doesn't have a way to get the entire buffer, only various sections of it. Being able to work with the entire buffer is useful in some situations, such as while building testing tools that limit the size of the buffer (similar to BufMut::limit in tokio 0.2).

Solution

Add ReadBuf::inner_mut which returns the entire inner buffer.

This is unsafe for the same reason that unfilled_mut is: the caller must not deinitialize portions of the buffer that have already been initialized.

I've used this method in partial-io: facebookarchive/rust-partial-io#33 (comment) and it looks like it does the job.

I'm not sure if any tests for this make sense, given the fact that the implementation is one line long.

Thank you!

@sunshowers
Copy link
Contributor Author

There's an upstream Rust RFC for ReadBuf, and i guess this should go there too?

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Jan 19, 2021
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

This seems good to me.

@sunshowers
Copy link
Contributor Author

Updated with a bit more documentation about the invariants calling code is expected to uphold.

This returns the entire buffer as a `&mut [MaybeUninit<u8>]`, which may
be useful for building abstractions on top.
@Darksonn
Copy link
Contributor

Prefer to push more commits instead of force-pushing.

@sunshowers
Copy link
Contributor Author

sunshowers commented Jan 19, 2021

Prefer to push more commits instead of force-pushing.

Hmm, I was going by the contributor guide, which recommends using logical commits and not checkpoints, and which is also my preferred style of contributions from personal experience. (Though later I do see that the guide talks about not rebasing/force pushing, which seems to contradict this?)

@Darksonn
Copy link
Contributor

It could be written clearer, yes. The point is that, once I have already looked at the PR, it is a lot easier to see what changed since I last looked if all changes are done as additional commits.

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.

2 participants