File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2633,6 +2633,21 @@ impl str {
26332633 self . as_bytes ( ) . as_ascii ( )
26342634 }
26352635
2636+ /// Converts this string slice into a slice of [ASCII characters](ascii::Char),
2637+ /// without checking whether they are valid.
2638+ ///
2639+ /// # Safety
2640+ ///
2641+ /// Every character in this string must be ASCII, or else this is UB.
2642+ #[ unstable( feature = "ascii_char" , issue = "110998" ) ]
2643+ #[ must_use]
2644+ #[ inline]
2645+ pub const unsafe fn as_ascii_unchecked ( & self ) -> & [ ascii:: Char ] {
2646+ // SAFETY: the caller promised that every byte of this string slice
2647+ // is ASCII.
2648+ unsafe { self . as_bytes ( ) . as_ascii_unchecked ( ) }
2649+ }
2650+
26362651 /// Checks that two strings are an ASCII case-insensitive match.
26372652 ///
26382653 /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
You can’t perform that action at this time.
0 commit comments