Make BorrowedBuf and BorrowedCursor generic over the data#149749
Make BorrowedBuf and BorrowedCursor generic over the data#149749joshtriplett wants to merge 6 commits into
BorrowedBuf and BorrowedCursor generic over the data#149749Conversation
|
☔ The latest upstream changes (presumably #150106) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
I think it'd be fine to land this PR for generic-izing the type, then we can land another PR right afterwards to remove the default and update the uses.
Code looks good to me, and I tried to scan for anything making unsaid assumptions about T (being Copy, Freeze, etc) and didn't find any that weren't already updated.
So r=me with conflicts fixed.
Aside: excited to try this out with generic types. Might be a great way to solve some of the Iterator::next_chunk or Vec::push_within_existing_capacity scenarios.
|
I'm going to wait to update this until after #150129 is merged. |
Replace uses of `u8` with a generic type. This will allow reusing `BorrowedBuf` elsewhere in the standard library, for purposes other than byte buffers. This currently requires `T: Copy`, to prevent `T: Drop`, which would require additional careful handling. We can consider relaxing that restriction in the future if we make `T: Drop` work (without pessimizing `Copy` types like `u8`). `ensure_init` currently continues to require `u8`. We could potentially generalize it to `T: Default`, but we'd need to ensure it produced the same or better assembly for `u8`.
c150931 to
f7b1581
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This default simplified the commit making these types generic, but we don't actually want the default. Rewrite every user to specify `u8` explicitly.
|
@rustbot ready This is ready for review. I would suggest looking at it commit by commit, as the change to remove the default |
|
r? libs |
View all comments
Replace uses of
u8with a generic type. This will allow reusingBorrowedBufelsewhere in the standard library, for purposes other thanbyte buffers.
This currently requires
T: Copy, to preventT: Drop, which would require additional careful handling. We can consider relaxing that restriction in the future if we makeT: Dropwork (without pessimizingCopytypes likeu8).ensure_initcurrently continues to requireu8. We could potentially generalize it toT: Default, but we'd need to ensure it produced the same or better assembly foru8.As discussed in libs-api; cc @Amanieu.