Repository navigation
Tracking Issue for const_vec_string_slice #129041
Copy link
Copy link
Closed
Labels
A-strArea: str and StringArea: str and StringC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Milestone
Description
Feature gate: #![feature(const_vec_string_slice)]
This is a tracking issue for making a bunch of String and Vec methods const.
Public API
The following methods are now const:
impl String {
pub const fn into_bytes(self) -> Vec<u8>;
pub const fn as_str(&self) -> &str;
pub const fn capacity(&self) -> usize;
pub const fn as_bytes(&self) -> &[u8];
pub const fn len(&self) -> usize;
pub const fn is_empty(&self) -> bool;
}
impl Vec<T> {
pub const fn capacity(&self) -> usize;
pub const fn as_slice(&self) -> &[T];
pub const fn as_ptr(&self) -> *const T;
pub const fn len(&self) -> usize;
pub const fn is_empty(&self) -> bool;
}A few additional methods are under this feature gate but were not included in the FCP at #129041 (comment); they got FCP'd in #137319 (comment):
impl String {
pub const fn as_mut_str(&mut self) -> &mut str;
pub const unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>;
}
impl Vec<T> {
pub const fn as_mut_slice(&mut self) -> &mut [T];
pub const fn as_mut_ptr(&mut self) -> *mut T;
}Steps / History
- Implementation: liballoc: introduce String, Vec const-slicing #128399
- Final comment period (FCP)1
- Stabilization PR: Stabilize
const_vec_string_slice#137319
Unresolved Questions
- None yet.
@rustbot label A-str
Footnotes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-strArea: str and StringArea: str and StringC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
Esper89 commentedon Aug 13, 2024
This would be very useful for
const fns that sometimes need to handle runtime data too, such as aconst fnmethod that needs to use aCow<'static, [T]>field.For example:
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
liballoc: introduce String, Vec const-slicing
RalfJung commentedon Nov 30, 2024
@rust-lang/libs-api from a const-eval perspective, these functions all look totally harmless. One can't actually construct non-trivial
Vec/Stringinconst, but according to the examples above it could still be useful to have these asconst fn. So, I propose we move ahead with stabilizing these.17 remaining items
Amanieu commentedon Feb 25, 2025
I started a new FCP on #137319.
Stabilize `const_vec_string_slice`
Stabilize `const_vec_string_slice`
Stabilize `const_vec_string_slice`
Rollup merge of rust-lang#137319 - Kixunil:stabilize-const-vec-string…
Rollup merge of rust-lang#137319 - Kixunil:stabilize-const-vec-string…
Unrolled build for rust-lang#137319
Stabilize `const_vec_string_slice`
Rollup merge of rust-lang#141467 - cyrgani:const-empty-stringlikes, r…
Unrolled build for #141467
Rollup merge of rust-lang#141467 - cyrgani:const-empty-stringlikes, r…