rust-lang / rust-lang/rust

Tracking Issue for const `IoSlice` and `IoSliceMut` methods

Open
#146,459 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-unimplemented T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(io_slice_const)]

This is a tracking issue for making the new and advance methods on IoSlice and IoSliceMut const.

In particular, this enables constructing IoSlice and IoSliceMut in const contexts without users needing to break the platform abstraction by doing the cast themselves. This is useful for statics.

Since all current and plausible future platforms use simple slice-like structs, this should not impose a burden when adding a new platform with a different struct.

Public API

Methods new and advance are made const for IoSlice and IoSliceMut. advance_slices is more complicated and remains non-const. into_slice/as_slice are unstably const and tracked separately.

// std::io

impl<'a> IoSliceMut<'a> {
    #[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
    pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a>;
    #[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
    pub const fn advance(&mut self, n: usize;

    // Other methods (unchanged):
    pub fn advance_slices(bufs: &mut &mut [IoSliceMut<'a>], n: usize);
    #[unstable(feature = "io_slice_as_bytes", issue = "132818")]
    pub const fn into_slice(self) -> &'a mut [u8];
}

impl<'a> IoSlice<'a> {
    #[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
    pub const fn new(buf: &'a [u8]) -> IoSlice<'a>;
    #[rustc_const_unstable(feature = "io_slice_const", issue = "146459")]
    pub const fn advance(&mut self, n: usize);

    // Other methods (unchanged):
    pub fn advance_slices(bufs: &mut &mut [IoSlice<'a>], n: usize);
    #[unstable(feature = "io_slice_as_bytes", issue = "132818")]
    pub const fn as_slice(self) -> &'a [u8];
}
Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions
  • None yet.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with linked implementation PR #144090 and the public API listed for IoSlice and IoSliceMut. Check the feature-gate history and stabilization process; done requires the implementation, final comment period, and stabilization PR steps to be completed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.