Skip to content

Tracking Issue for const IoSlice and IoSliceMut methods #146459

@thaliaarchi

Description

@thaliaarchi

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 = "none")]
    pub const fn new(buf: &'a mut [u8]) -> IoSliceMut<'a>;
    #[rustc_const_unstable(feature = "io_slice_const", issue = "none")]
    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 = "none")]
    pub const fn new(buf: &'a [u8]) -> IoSlice<'a>;
    #[rustc_const_unstable(feature = "io_slice_const", issue = "none")]
    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.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions