Skip to content

Commit 43fc0ee

Browse files
committed
Constify AsciiChar::is_digit()
Now all AsciiChar methods are const fn.
1 parent 88b717c commit 43fc0ee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ascii_char.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ impl AsciiChar {
436436
///
437437
/// Radixes greater than 36 are not supported and will result in a panic.
438438
#[must_use]
439-
pub fn is_digit(self, radix: u32) -> bool {
439+
pub const fn is_digit(self, radix: u32) -> bool {
440440
match (self as u8, radix) {
441-
(b'0'..=b'9', 0..=36) => u32::from(self as u8 - b'0') < radix,
442-
(b'a'..=b'z', 11..=36) => u32::from(self as u8 - b'a') < radix - 10,
443-
(b'A'..=b'Z', 11..=36) => u32::from(self as u8 - b'A') < radix - 10,
441+
(b'0'..=b'9', 0..=36) => (self as u32 - '0' as u32) < radix,
442+
(b'a'..=b'z', 11..=36) => (self as u32 - 'a' as u32) < radix - 10,
443+
(b'A'..=b'Z', 11..=36) => (self as u32 - 'A' as u32) < radix - 10,
444444
(_, 0..=36) => false,
445445
(_, _) => panic!("radixes greater than 36 are not supported"),
446446
}

0 commit comments

Comments
 (0)