Skip to content

Commit e8c19d4

Browse files
committed
Constify AsciiChar::is_digit()
Now all AsciiChar methods are const fn.
1 parent fb8b234 commit e8c19d4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ascii_char.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,11 @@ impl AsciiChar {
439439
///
440440
/// Radixes greater than 36 are not supported and will result in a panic.
441441
#[must_use]
442-
pub fn is_digit(self, radix: u32) -> bool {
442+
pub const fn is_digit(self, radix: u32) -> bool {
443443
match (self as u8, radix) {
444-
(b'0'..=b'9', 0..=36) => u32::from(self as u8 - b'0') < radix,
445-
(b'a'..=b'z', 11..=36) => u32::from(self as u8 - b'a') < radix - 10,
446-
(b'A'..=b'Z', 11..=36) => u32::from(self as u8 - b'A') < radix - 10,
444+
(b'0'..=b'9', 0..=36) => (self as u32 - '0' as u32) < radix,
445+
(b'a'..=b'z', 11..=36) => (self as u32 - 'a' as u32) < radix - 10,
446+
(b'A'..=b'Z', 11..=36) => (self as u32 - 'A' as u32) < radix - 10,
447447
(_, 0..=36) => false,
448448
(_, _) => panic!("radixes greater than 36 are not supported"),
449449
}

0 commit comments

Comments
 (0)