-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[u8] methods in libcore? #45803
Copy link
Copy link
Closed
Labels
C-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Background on [T] methods
Inherent methods for slices are currently defined in liballoc with:
#[lang(slice)]is an escape hatch to allow that impl to exist. Normally it wouldn’t be allowed since liballoc is not the crate that defined slices types. (No such crate exists.) The compiler only allows one#[lang(slice)]item to exist, so we have it in liballoc where it can define every method we want slices to have.So in
#![no_std]crates that do not depend on liballoc, slices have no inherent methods. Instead, libcore has acore::slice::SliceExttrait implemented for[T]that has a subset of the methods and needs to be imported into scope to be used.Background on [u8] methods
#44042 added inherent methods specific to byte slices. They’re also in liballoc, with a new dedicated lang item:
But they’re not available without liballoc, although they don’t all depend on allocation.
Now
It’d be nice to have some of these
[u8]methods without liballoc. The simple thing would be to continue this pattern and add acore::slice::SliceU8Exttrait, but that doesn’t seem like very good design.Maybe it’s time to revisit
SliceExt. Could the “only one#[lang(slice)]” restriction be lifted? Or could we add newcore_sliceandcore_slice_u8lang items?CC @eddyb