diff --git a/src/ascii_char.rs b/src/ascii_char.rs index 39f2ceb..d2803f8 100644 --- a/src/ascii_char.rs +++ b/src/ascii_char.rs @@ -468,15 +468,15 @@ impl AsciiChar { /// /// # Panics /// - /// Radixes greater than 36 are not supported and will result in a panic. + /// Panics if given a radix smaller than 2 or larger than 36. #[must_use] pub fn is_digit(self, radix: u32) -> bool { match (self as u8, radix) { - (b'0'..=b'9', 0..=36) => u32::from(self as u8 - b'0') < radix, + (b'0'..=b'9', 2..=36) => u32::from(self as u8 - b'0') < radix, (b'a'..=b'z', 11..=36) => u32::from(self as u8 - b'a') < radix - 10, (b'A'..=b'Z', 11..=36) => u32::from(self as u8 - b'A') < radix - 10, - (_, 0..=36) => false, - (_, _) => panic!("radixes greater than 36 are not supported"), + (_, 2..=36) => false, + (_, _) => panic!("radix must be in the range 2 to 36 inclusive"), } } @@ -704,7 +704,7 @@ impl AsciiChar { // the unprintable characters from 0x0 to 0x1f, ordered correctly. // As `b` is guaranteed to be within 0x0 to 0x1f, the conversion represents a // valid character. - b @ 0x0..=0x1f => unsafe { mem::transmute('␀' as u32 + b as u32) }, + b @ 0x0..=0x1f => unsafe { char::from_u32_unchecked('␀' as u32 + b as u32) }, // 0x7f (delete) has it's own character at codepoint 0x2420, not 0x247f, so it is special // cased to return it's character @@ -794,8 +794,8 @@ macro_rules! impl_into_partial_eq_ord { ($wider:ty, $to_wider:expr) => { impl From for $wider { #[inline] - fn from(a: AsciiChar) -> $wider { - $to_wider(a) + fn from(chr: AsciiChar) -> $wider { + $to_wider(chr) } } impl PartialEq<$wider> for AsciiChar { @@ -1050,15 +1050,22 @@ mod tests { #[test] fn is_digit_strange_radixes() { - assert_eq!(AsciiChar::_0.is_digit(0), '0'.is_digit(0)); - assert_eq!(AsciiChar::_0.is_digit(1), '0'.is_digit(1)); + assert_eq!(AsciiChar::_0.is_digit(2), '0'.is_digit(2)); + assert_eq!(AsciiChar::_1.is_digit(2), '1'.is_digit(2)); + assert_eq!(AsciiChar::_2.is_digit(2), '2'.is_digit(2)); assert_eq!(AsciiChar::_5.is_digit(5), '5'.is_digit(5)); assert_eq!(AsciiChar::z.is_digit(35), 'z'.is_digit(35)); } #[test] #[should_panic] - fn is_digit_bad_radix() { + fn is_digit_bad_radix_small() { + let _ = AsciiChar::_0.is_digit(1); + } + + #[test] + #[should_panic] + fn is_digit_bad_radix_big() { let _ = AsciiChar::_7.is_digit(37); } diff --git a/src/ascii_str.rs b/src/ascii_str.rs index bfdf54e..3568e85 100644 --- a/src/ascii_str.rs +++ b/src/ascii_str.rs @@ -226,7 +226,7 @@ impl AsciiStr { /// Returns an iterator over the characters of the `AsciiStr`. #[inline] #[must_use] - pub fn chars(&self) -> Chars { + pub fn chars(&self) -> Chars<'_> { Chars(self.slice.iter()) } @@ -234,7 +234,7 @@ impl AsciiStr { /// value of each `AsciiChar`. #[inline] #[must_use] - pub fn chars_mut(&mut self) -> CharsMut { + pub fn chars_mut(&mut self) -> CharsMut<'_> { CharsMut(self.slice.iter_mut()) }