Skip to content

Move std::io::copy internals to alloc::io#158548

Open
bushrat011899 wants to merge 22 commits into
rust-lang:mainfrom
bushrat011899:alloc_io_copy_internals
Open

Move std::io::copy internals to alloc::io#158548
bushrat011899 wants to merge 22 commits into
rust-lang:mainfrom
bushrat011899:alloc_io_copy_internals

Conversation

@bushrat011899

@bushrat011899 bushrat011899 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

ACP: rust-lang/libs-team#755
Tracking issue: #154046
Split From: #156527
Blocked On: #158547

Description

Moves the generic implementation of std::io::copy to alloc::io. This is effectively a direct cut and paste. Blocked on #158547.

Worth considering is how we may want to expose the generic copy function for end users. Currently, std only exposes std::io::copy, which internally uses kernel_copy and falls back onto generic_copy as required. We could expose generic_copy as alloc::io::copy, but then alloc::io::copy and std::io::copy would be different functions. There are instances where that already happens (core::panic! is not the same as std::panic! for example), but this would be an easy mistake to make with performance implications.

Alternatively, EII could allow the kernel_copy function to be provided to alloc, so the full copy function is defined in alloc::io and then reexported in std::io. But that's dependent on EII being more stable.

For now, this PR just moves generic_copy to signal that the full std::io::copy is very close to being able to be moved into alloc::io.


Notes

Used to work around `Cursor` not being a fundamental type when implementing `Write` for `Cursor<Vec<u8>>` and other `alloc` types once `Cursor` and `Write` are both located in `core`.
Call to `<&mut [u8] as Write>::write` inlined as `Write` trait not yet moved into `core`.
None of the currently public methods are accessible outside `std`, and are unused within. Therefore, they can be restricted to internal use.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 29, 2026
@rustbot

rustbot commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 6 candidates

@bushrat011899

Copy link
Copy Markdown
Contributor Author

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants