-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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_strCString::as_bytesCString::as_bytes_with_nulCString::into_bytesCString::into_bytes_with_nulCString::into_stringc_str::FromVecWithNulError::as_bytesc_str::FromVecWithNulError::into_bytesc_str::IntoStringError::into_cstringc_str::IntoStringError::utf8_errorBox<[T]>::into_vec<Box<str>>::into_boxed_bytes<Box<str>>::into_stringString::from_utf8String::from_utf8_uncheckedstring::FromUtf8Error::as_bytesstring::FromUtf8Error::into_bytesstring::FromUtf8Error::utf8_errorOsString::as_os_str<Box<OsStr>>::into_os_stringPathBuf::as_pathpath::{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: Constify conversion traits #144289
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should
PrefixComponentbe givenAsRef<OsStr>andAsRef<Path>impls? (these are indirectly used forComponent's implementation, but it doesn't have them itself)