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

Lines changed: 4 additions & 4 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy