-
-
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 ReadBuf::inner_mut #3443
Conversation
There's an upstream Rust RFC for ReadBuf, and i guess this should go there too? |
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.
This seems good to me.
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.
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?) |
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. |
This returns the entire buffer as a
&mut [MaybeUninit<u8>]
, which maybe 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 toBufMut::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!