Implement Write for Cursor<W: AsMut<[u8]>> - #160960
Open
bushrat011899 wants to merge 1 commit into
Open
Conversation
Collaborator
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This was referenced Aug 12, 2026
This comment has been minimized.
This comment has been minimized.
Change `WriteThroughCursor` into a specialization which allows `Vec` and `&mut Vec` to extend their allocation for writing. This makes discoverability of the `Write` implementation better.
bushrat011899
force-pushed
the
core_io_cursor_write_rewrite
branch
from
August 12, 2026 22:07
517f9a5 to
8142083
Compare
Collaborator
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
WriteThroughCursorinto a specialization which allowsVecand&mut Vecto extend their allocation for writing. This makes discoverability of theWriteimplementation better.ACP: rust-lang/libs-team#853
Tracking Issue: #154046
Follow Up To: #160952 & #158537
Description
Currently,
Writeis implemented forCursor<W>, whereWis one of:&mut [u8]for<const N: usize> [u8; N]for<A: Allocator> Box<[u8], A>for<A: Allocator> Vec<u8, A>for<A: Allocator> &mut Vec<u8, A>When moving
Writeintocore::io, it was noted here that the documentation ofCursorwould be degraded due to the introduction ofWriteThroughCursor, an indirection trait to allowCursorandWriteincore, whileBoxandVecexist inalloc.To resolve this documentation regression, and add additional functionality as well, I'm proposing we instead implement
Write for Cursor<W>whereW: AsMut<[u8]>. All 5 of the original types above implementAsMut<[u8]>, so we'll correctly document the breadth of support.However, for
Vecand&mut Vec, I use specialization to allow their implementation to extend, rather than only writing to the existing slice. While this still uses an indirection trait (SpecCursorWrite), but now this is purely for specialization, and therefore doesn't need to be documented publicly.I'm opening a PR directly as a reference point, but I suspect this will need an ACP since this changes the public API.
Notes