-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add {IoSlice, IoSliceMut}::advance #62987
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Thanks for the PR! As a convenience function though I would imagine that wouldn't this be more useful if defined on something like |
I agree, that is what I need for rust-lang/futures-rs#1741 as well. I'm fine with changing it. But where would I put the code for such a change? In the |
Perhaps something like: impl IoVec<'_> {
pub fn advance(slice: &mut [IoVec]) { /* ... */ }
}
impl IoVecMut<'_> {
pub fn advance(slice: &mut [IoVecMut]) { /* ... */ }
} or something like that? |
Looks good, I'll try to update the pr tomorrow. |
src/libstd/io/mod.rs
Outdated
/// | ||
/// # Notes | ||
/// | ||
/// Elements in the slice may be modified. |
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 might need expanding.
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.
Yeah I'd recommend going into detail here and explaining how the vector elements of the slice may be modified to adjust the size as noted by advance
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.
What do you think of what I've added?
I've addressed all comments and updated the API to return the truncated slice. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
/// | ||
/// Elements in the slice may be modified. | ||
/// | ||
/// # Examples |
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.
The documentation here I think may also want to mention that this API panics if you advance beyond the cumulative size of all buffers.
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.
But it doesn't panic if you go beyond the cumulative size, see the io_slice_advance_beyond_total_length
test.
src/libstd/io/mod.rs
Outdated
/// | ||
/// # Notes | ||
/// | ||
/// Elements in the slice may be modified. |
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.
Yeah I'd recommend going into detail here and explaining how the vector elements of the slice may be modified to adjust the size as noted by advance
/// ][..]; | ||
/// | ||
/// // Mark 10 bytes as read. | ||
/// bufs = IoSliceMut::advance(mem::replace(&mut bufs, &mut []), 10); |
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'm not too fond of this mem::replace
dance we have to do.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The commits have become a bit messy, I'll squash them before merging once the review is complete. |
Ok everything looks great to me, thanks! If you want to do some cleanup feel free! @bors: delegate+ |
✌️ @Thomasdezeeuw can now approve this pull request |
This is ready now, I've squashed the commits and rebased on master. |
Hope this works. @bors r+ |
📌 Commit dad56c3 has been approved by |
⌛ Testing commit dad56c3 with merge ebaa05e81052cc5f04d68880275ba073021d5f9a... |
…omasdezeeuw Add {IoSlice, IoSliceMut}::advance API inspired by the [`Buf::advance`](https://docs.rs/bytes/0.4.12/bytes/trait.Buf.html#tymethod.advance) method found in the [bytes](https://docs.rs/bytes) crate. Closes rust-lang#62726.
panic!("advancing IoSliceMut beyond its length"); | ||
} | ||
|
||
unsafe { |
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.
Could we always uphold the minimum standard of having comments on all unsafe {
blocks?
I think that's something you should be able to expect of something so central as the standard library.
@bors retry rolled up. |
⌛ Testing commit dad56c3 with merge 1828a3f06b20e9c99e443d2a99fd424016735a05... |
@bors retry yielding to r0llup. |
⌛ Testing commit dad56c3 with merge 015346c142811b881b28c5e81c1b27e59fe286d8... |
@bors retry yielding to r0llup. |
Add {IoSlice, IoSliceMut}::advance API inspired by the [`Buf::advance`](https://docs.rs/bytes/0.4.12/bytes/trait.Buf.html#tymethod.advance) method found in the [bytes](https://docs.rs/bytes) crate. Closes #62726.
☀️ Test successful - checks-azure |
API inspired by the
Buf::advance
method found in the bytes crate.Closes #62726.