File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2633,6 +2633,21 @@ impl str {
2633
2633
self . as_bytes ( ) . as_ascii ( )
2634
2634
}
2635
2635
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
+
2636
2651
/// Checks that two strings are an ASCII case-insensitive match.
2637
2652
///
2638
2653
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
You can’t perform that action at this time.
0 commit comments