rust-lang / rust-lang/rust

Tracking Issue for const conversion methods that don't require const traits

Open
#144,288 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(const_convert_methods)]

This is a tracking issue for various methods used in the constification of the Deref and DerefMut traits which could be stabilised before const traits are stabilised. These methods themselves do not depend on any traits in their APIs and can be implemented in a way that does not use unstable const traits.

Public API

Constness is added to the following methods:

  • Box::into_boxed_slice (Box<T> -> Box<[T]>)
  • Box::into_pin (Box<T> -> Pin<Box<T>>)
  • CString::as_c_str
  • CString::as_bytes
  • CString::as_bytes_with_nul
  • CString::into_bytes
  • CString::into_bytes_with_nul
  • CString::into_string
  • c_str::FromVecWithNulError::as_bytes
  • c_str::FromVecWithNulError::into_bytes
  • c_str::IntoStringError::into_cstring
  • c_str::IntoStringError::utf8_error
  • Box<[T]>::into_vec
  • <Box<str>>::into_boxed_bytes
  • <Box<str>>::into_string
  • String::from_utf8
  • String::from_utf8_unchecked
  • string::FromUtf8Error::as_bytes
  • string::FromUtf8Error::into_bytes
  • string::FromUtf8Error::utf8_error
  • OsString::as_os_str
  • <Box<OsStr>>::into_os_string
  • PathBuf::as_path
  • path::{Component, PrefixComponent}::as_os_str
  • <Box<Path>>::into_path_buf
Explicitly Excluded APIs

While conversions from boxes to other collections are supported, because the reverse direction involves removing excess capacity, those conversions are omitted.

Although CString currently uses Box<[u8]> internally, this is an implementation detail that isn't relied upon. However, it also does prevent conversions from Vec for similar reasons.

Explicitly because the nul byte on CStrings can be popped off without deallocating, CString::into_bytes is made const.

Steps / History

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

  • Implementation: #144289
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Should PrefixComponent be given AsRef<OsStr> and AsRef<Path> impls? (these are indirectly used for Component's implementation, but it doesn't have them itself)

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 implementation issue #144289 and the listed standard-library APIs; this tracking issue names no source files or tests. Check the implementation, final comment period, and stabilization steps, including the unresolved PrefixComponent question, to determine whether the feature is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
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.