Constify [u8]::is_ascii (unstably)

UTF-8 checking in `const fn`-stabilized back in 1.63, but apparently somehow ASCII checking was never const-ified, despite being simpler.
This commit is contained in:
Scott McMurray
2023-05-04 14:26:19 -07:00
parent eb7a743421
commit 370d31b93d
4 changed files with 35 additions and 15 deletions

View File

@@ -7,7 +7,7 @@ impl<const N: usize> [u8; N] {
#[unstable(feature = "ascii_char", issue = "110998")]
#[must_use]
#[inline]
pub fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
pub const fn as_ascii(&self) -> Option<&[ascii::Char; N]> {
if self.is_ascii() {
// SAFETY: Just checked that it's ASCII
Some(unsafe { self.as_ascii_unchecked() })