Skip to content

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

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

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

Conversation

@bushrat011899

@bushrat011899 bushrat011899 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

View all comments

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

Description

Moves std::io::copy into alloc::io. Blocked on #158547.

This relies on specialization to allow std to provide optimised copy implementations for its types where appropriate. The exact technique involves defining a new trait, alloc::io::SpecCopy:

#[doc(hidden)]
#[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")]
#[rustc_specialization_trait]
pub trait SpecCopy: Read {
    /// Attempt to copy from this reader to the provided writer using a specialized
    /// process.
    fn copy<R: Read + ?Sized, W: Write + ?Sized>(
        _reader: &mut R,
        _writer: &mut W,
    ) -> Result<CopyState>;
}

Since optimised copying requires both the reader and writer to support the operation between each other, we can choose one of them to be the implementer of the copy algorithm, and delegate specialization to it. In this case, I've chosen the reader to be the provider of the specialized copy implementation arbitrarily. Note that the SpecCopy::copy function is generic over the reader specifically to allow wrappers like Take<R> to be visible to the implementation of copy.

Because this introduces a new layer of specialization to io::copy, I think this PR should be benchmarked to make sure performance characteristics aren't too different. I am expecting compilation time to be slightly worse, since there's just more specialization happening, but the actual code run should be the same.


Notes

@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
@rust-bors

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 1bcdfe1 to 43f67ba Compare July 2, 2026 02:01
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch 2 times, most recently from 90ec159 to 8139972 Compare July 3, 2026 03:50
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 8139972 to cb62676 Compare July 6, 2026 09:26
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from cb62676 to 3bb0364 Compare July 6, 2026 21:51
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 3bb0364 to df9a018 Compare July 6, 2026 22:21
@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from df9a018 to 8f363d9 Compare July 7, 2026 05:28
@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 8f363d9 to d331e98 Compare July 8, 2026 09:09
@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from d331e98 to 386eee0 Compare July 10, 2026 05:26
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 386eee0 to fc0fada Compare July 18, 2026 03:25
@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from fc0fada to d6335a5 Compare July 18, 2026 21:35
@rustbot

This comment has been minimized.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch 2 times, most recently from 875bdd0 to f09db87 Compare July 19, 2026 21:54
@rustbot

rustbot commented Jul 19, 2026

Copy link
Copy Markdown
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.

@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from f09db87 to 58612c3 Compare July 20, 2026 04:37
@bushrat011899 bushrat011899 changed the title Move std::io::copy internals to alloc::io Move std::io::copy to alloc::io Jul 20, 2026
bushrat011899 and others added 6 commits July 20, 2026 15:00
None of the currently public methods are accessible outside `std`, and are unused within. Therefore, they can be restricted to internal use.
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 58612c3 to 8ea8fc7 Compare July 20, 2026 05:21
@rust-log-analyzer

This comment has been minimized.

bushrat011899 and others added 4 commits July 20, 2026 17:14
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
Rely on specialization to allow `std` to provide optimized copy implementations.
@bushrat011899
bushrat011899 force-pushed the alloc_io_copy_internals branch from 8ea8fc7 to dd93f8e Compare July 20, 2026 07:15
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.

4 participants