We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46d4f99 commit 82f93a2Copy full SHA for 82f93a2
library/core/src/num/mod.rs
@@ -482,6 +482,20 @@ impl u8 {
482
ascii::Char::from_u8(*self)
483
}
484
485
+ /// Converts this byte to an [ASCII character](ascii::Char), without
486
+ /// checking whether or not it's valid.
487
+ ///
488
+ /// # Safety
489
490
+ /// This byte must be valid ASCII, or else this is UB.
491
+ #[must_use]
492
+ #[unstable(feature = "ascii_char", issue = "110998")]
493
+ #[inline]
494
+ pub const unsafe fn as_ascii_unchecked(&self) -> ascii::Char {
495
+ // SAFETY: the caller promised that this byte is ASCII.
496
+ unsafe { ascii::Char::from_u8_unchecked(*self) }
497
+ }
498
+
499
/// Makes a copy of the value in its ASCII upper case equivalent.
500
///
501
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
0 commit comments