@@ -375,9 +375,9 @@ impl AsciiChar {
375
375
/// and `Some(AsciiChar::from_ascii_unchecked(128))` might be `None`.
376
376
#[ inline]
377
377
#[ must_use]
378
- pub unsafe fn from_ascii_unchecked ( ch : u8 ) -> Self {
378
+ pub const unsafe fn from_ascii_unchecked ( ch : u8 ) -> Self {
379
379
// SAFETY: Caller guarantees `ch` is within bounds of ascii.
380
- unsafe { ch . to_ascii_char_unchecked ( ) }
380
+ unsafe { mem :: transmute ( ch ) }
381
381
}
382
382
383
383
/// Converts an ASCII character into a `u8`.
@@ -659,14 +659,15 @@ impl AsciiChar {
659
659
/// assert_eq!(AsciiChar::new('p').as_printable_char(), 'p');
660
660
/// ```
661
661
#[ must_use]
662
- pub fn as_printable_char ( self ) -> char {
662
+ pub const fn as_printable_char ( self ) -> char {
663
+ #![ allow( clippy:: transmute_int_to_char) ] // from_utf32_unchecked() is not const fn yet.
663
664
match self as u8 {
664
665
// Non printable characters
665
666
// SAFETY: From codepoint 0x2400 ('␀') to 0x241f (`␟`), there are characters representing
666
667
// the unprintable characters from 0x0 to 0x1f, ordered correctly.
667
668
// As `b` is guaranteed to be within 0x0 to 0x1f, the conversion represents a
668
669
// valid character.
669
- b @ 0x0 ..=0x1f => unsafe { char :: from_u32_unchecked ( u32 :: from ( '␀' ) + u32:: from ( b ) ) } ,
670
+ b @ 0x0 ..=0x1f => unsafe { mem :: transmute ( '␀' as u32 + b as u32 ) } ,
670
671
671
672
// 0x7f (delete) has it's own character at codepoint 0x2420, not 0x247f, so it is special
672
673
// cased to return it's character
0 commit comments