diff --git a/CHANGELOG.md b/CHANGELOG.md index 80b8e4f96..a25774c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v0.5.0 (2024-02-09) + +**Major Changes** + +* Adds a new function `CountDigits::checked_count_digits_radix()` which is a non-panicking +version of `CountDigits::count_digits_radix()`. + ## v0.4.0 (2024-02-08) **Major Changes** diff --git a/Cargo.toml b/Cargo.toml index 695f4f6a9..15aaa167d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "count-digits" -version = "0.4.0" +version = "0.5.0" authors = ["Erik Nordin "] description = "A no-std trait to count the digits of integer types in various number bases." homepage = "https://github.com/nordzilla/count-digits" diff --git a/README.md b/README.md index 7e7751604..0857241d2 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,12 @@ pub trait CountDigits: Copy + Sized { fn count_digits(self) -> usize; /// Returns the count of digits in an integer for a given radix. + /// Panics if the provided radix is invalid. fn count_digits_radix(self, radix: Self::Radix) -> usize; + + /// Returns the count of digits in an integer for a given radix. + /// Returns None if the given radix is invalid. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option; } ``` @@ -60,6 +65,10 @@ assert_eq!(04_usize, 0xF00D.count_digits_radix(16_u32)); assert_eq!(05_usize, 61453.count_digits()); assert_eq!(05_usize, 61453.count_digits_radix(10_u32)); + +assert!(1.checked_count_digits_radix(0_u32).is_none()); +assert!(1.checked_count_digits_radix(1_u32).is_none()); +assert!(1.checked_count_digits_radix(2_u32).is_some()); ``` The named functions for which the radix is a power of two ( @@ -75,8 +84,8 @@ assert_eq!(0b1011__i32.count_bits(), i32::BITS - 0b1011__i32.leading_zeros()); assert_eq!(0b1011_u128.count_bits(), u128::BITS - 0b1011_u128.leading_zeros()); ``` -The base-10 [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits) -function returns [usize](https://doc.rust-lang.org/core/primitive.usize.html) for compatibility with Rust's formatting macros. +The base-10 function [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits) +returns [usize](https://doc.rust-lang.org/core/primitive.usize.html) for compatibility with Rust's formatting macros. ```rust let max_digits = [1, 2, 15, 105] @@ -92,7 +101,9 @@ for n in [1, 2, 15, 105] { In the case of formatting binary, octal, or hex numbers, the [count_digits_radix(2 | 8 | 16)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits_radix) -function can be used to retrieve the desired count directly as a [usize](https://doc.rust-lang.org/core/primitive.usize.html). +and [checked_count_digits_radix(2 | 8 | 16)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.checked_count_digits_radix) +functions can be used to retrieve the desired count directly as a [usize](https://doc.rust-lang.org/core/primitive.usize.html), or +the value can simply be cast using the [as](https://doc.rust-lang.org/std/keyword.as.html) keyword. ```rust let max_bits = [0b1, 0b10, 0b101, 0b1011] @@ -109,10 +120,11 @@ for n in [0b1, 0b10, 0b101, 0b1011] { --- > [!NOTE] -> The base-10 functions -> [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits) -> and [count_digits_radix(10)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits_radix) -> do not include the negative sign in their counts. +> Function calls that count digits in base 10 ( +> [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits), +> [count_digits_radix(10)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits_radix), and +> [checked_count_digits_radix(10)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.checked_count_digits_radix) +> ) do not include the negative sign in their counts because the negative sign is not a digit. ```rust assert_eq!(5, 12345_i32.wrapping_neg().count_digits()); diff --git a/src/lib.rs b/src/lib.rs index f5e47c600..b3b54a5c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,7 +40,12 @@ //! fn count_digits(self) -> usize; //! //! /// Returns the count of digits in an integer for a given radix. +//! /// Panics if the provided radix is invalid. //! fn count_digits_radix(self, radix: Self::Radix) -> usize; +//! +//! /// Returns the count of digits in an integer for a given radix. +//! /// Returns None if the given radix is invalid. +//! fn checked_count_digits_radix(self, radix: Self::Radix) -> Option; //! } //! ``` //! @@ -61,6 +66,10 @@ //! //! assert_eq!(05_usize, 61453.count_digits()); //! assert_eq!(05_usize, 61453.count_digits_radix(10_u32)); +//! +//! assert!(1.checked_count_digits_radix(0_u32).is_none()); +//! assert!(1.checked_count_digits_radix(1_u32).is_none()); +//! assert!(1.checked_count_digits_radix(2_u32).is_some()); //! ``` //! //! The named functions for which the radix is a power of two ( @@ -77,8 +86,8 @@ //! assert_eq!(0b1011_u128.count_bits(), u128::BITS - 0b1011_u128.leading_zeros()); //! ``` //! -//! The base-10 [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits) -//! function returns [usize](https://doc.rust-lang.org/core/primitive.usize.html) for compatibility with Rust's formatting macros. +//! The base-10 function [count_digits()](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits) +//! returns [usize](https://doc.rust-lang.org/core/primitive.usize.html) for compatibility with Rust's formatting macros. //! //! ```rust //! # use count_digits::CountDigits; @@ -95,7 +104,9 @@ //! //! In the case of formatting binary, octal, or hex numbers, the //! [count_digits_radix(2 | 8 | 16)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.count_digits_radix) -//! function can be used to retrieve the desired count directly as a [usize](https://doc.rust-lang.org/core/primitive.usize.html). +//! and [checked_count_digits_radix(2 | 8 | 16)](https://docs.rs/count-digits/latest/count_digits/trait.CountDigits.html#tymethod.checked_count_digits_radix) +//! functions can be used to retrieve the desired count directly as a [usize](https://doc.rust-lang.org/core/primitive.usize.html), or +//! the value can simply be cast using the [as](https://doc.rust-lang.org/std/keyword.as.html) keyword. //! //! ```rust //! # use count_digits::CountDigits; @@ -113,15 +124,17 @@ //! --- //! //!
-//! The base-10 functions +//! Functions calls that count digits in base 10 ( //! //! count_digits() -//! -//! and +//! , //! //! count_digits_radix(10) +//! , and +//! +//! checked_count_digits_radix(10) //! -//! do not include the negative sign in their counts. +//! ) do not include the negative sign in their counts because the negative sign is not a digit. //!
//! //! ```rust @@ -537,7 +550,7 @@ pub trait CountDigits: Copy + Sized { /// Returns the count of decimal digits in an integer. /// ///
- /// Does not count the negative sign when counting negative, signed integers. + /// Does not count the negative sign when counting negative, signed integers because the negative sign is not a digit. ///
/// /// # Examples @@ -649,8 +662,12 @@ pub trait CountDigits: Copy + Sized { /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). /// + /// [Panics](panic) if the provided radix is 0 or 1. + /// + /// See [checked_count_digits_radix()](CountDigits::checked_count_digits_radix) for a non-panicking version of this function. + /// ///
- /// For radix 10, does not count the negative sign when counting negative, signed integers. + /// For radix 10, does not count the negative sign when counting negative, signed integers because the negative sign is not a digit. /// /// For all other radix values, counts digits according to the /// twos-complement representation. @@ -661,14 +678,46 @@ pub trait CountDigits: Copy + Sized { /// ```rust /// use count_digits::CountDigits; /// - /// for n in 0..1_000_000 { + /// for n in 0..100 { + /// assert!(std::panic::catch_unwind(|| n.count_digits_radix(0_u32)).is_err()); + /// assert!(std::panic::catch_unwind(|| n.count_digits_radix(1_u32)).is_err()); + /// /// assert_eq!(n.count_digits_radix(02_u32) as u32, n.count_bits()); /// assert_eq!(n.count_digits_radix(08_u32) as u32, n.count_octal_digits()); - /// assert_eq!(n.count_digits_radix(10_u32), n.count_digits()); /// assert_eq!(n.count_digits_radix(16_u32) as u32, n.count_hex_digits()); + /// assert_eq!(n.count_digits_radix(10_u32), n.count_digits()); /// } /// ``` fn count_digits_radix(self, radix: Self::Radix) -> usize; + + /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// Returns [None] if the provided radix is 0 or 1. + /// + /// See [count_digits_radix()](CountDigits::count_digits_radix) for a panicking version of this function. + /// + ///
+ /// For radix 10, does not count the negative sign when counting negative, signed integers because the negative sign is not a digit. + /// + /// For all other radix values, counts digits according to the + /// twos-complement representation. + ///
+ /// + /// # Examples + /// + /// ```rust + /// use count_digits::CountDigits; + /// + /// for n in 0..100 { + /// assert_eq!(n.checked_count_digits_radix(00_u32), None); + /// assert_eq!(n.checked_count_digits_radix(01_u32), None); + /// assert_eq!(n.checked_count_digits_radix(02_u32).unwrap() as u32, n.count_bits()); + /// assert_eq!(n.checked_count_digits_radix(08_u32).unwrap() as u32, n.count_octal_digits()); + /// assert_eq!(n.checked_count_digits_radix(16_u32).unwrap() as u32, n.count_hex_digits()); + /// assert_eq!(n.checked_count_digits_radix(10_u32).unwrap(), n.count_digits()); + /// } + /// ``` + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option; } macro_rules! impl_count_digits { @@ -721,6 +770,10 @@ macro_rules! impl_count_digits { #[inline(always)] /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// [Panics](panic) if the provided radix is 0 or 1. + /// + /// See [checked_count_digits_radix()](CountDigits::checked_count_digits_radix) for a non-panicking version of this function. fn count_digits_radix(self, radix: Self::Radix) -> usize { match radix { 0 | 1 => panic!("base of integer logarithm must be at least 2"), @@ -737,6 +790,19 @@ macro_rules! impl_count_digits { } } } + + #[inline(always)] + /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// Returns [None] if the provided radix is 0 or 1. + /// + /// See [count_digits_radix()](CountDigits::count_digits_radix) for a panicking version of this function. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option { + match radix { + 0 | 1 => None, + radix => Some(self.count_digits_radix(radix)), + } + } } impl CountDigits for $non_zero_type { @@ -780,6 +846,10 @@ macro_rules! impl_count_digits { #[inline(always)] /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// [Panics](panic) if the provided radix is 0 or 1. + /// + /// See [checked_count_digits_radix()](CountDigits::checked_count_digits_radix) for a non-panicking version of this function. fn count_digits_radix(self, radix: Self::Radix) -> usize { match radix { 0 | 1 => panic!("base of integer logarithm must be at least 2"), @@ -796,6 +866,19 @@ macro_rules! impl_count_digits { } } } + + #[inline(always)] + /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// Returns [None] if the provided radix is 0 or 1. + /// + /// See [count_digits_radix()](CountDigits::count_digits_radix) for a panicking version of this function. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option { + match radix { + 0 | 1 => None, + radix => Some(self.count_digits_radix(radix)), + } + } } }; ( @@ -831,6 +914,10 @@ macro_rules! impl_count_digits { #[inline(always)] /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// [Panics](panic) if the provided radix is 0 or 1. + /// + /// See [checked_count_digits_radix()](CountDigits::checked_count_digits_radix) for a non-panicking version of this function. fn count_digits_radix(self, radix: Self::Radix) -> usize { match radix { 0 | 1 => panic!("base of integer logarithm must be at least 2"), @@ -841,6 +928,19 @@ macro_rules! impl_count_digits { __ => 1 + self.checked_ilog(radix).unwrap_or_default() as usize, } } + + #[inline(always)] + /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// Returns [None] if the provided radix is 0 or 1. + /// + /// See [count_digits_radix()](CountDigits::count_digits_radix) for a panicking version of this function. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option { + match radix { + 0 | 1 => None, + radix => Some(self.count_digits_radix(radix)), + } + } } impl CountDigits for $non_zero_type { @@ -872,6 +972,10 @@ macro_rules! impl_count_digits { #[inline(always)] /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// [Panics](panic) if the provided radix is 0 or 1. + /// + /// See [checked_count_digits_radix()](CountDigits::checked_count_digits_radix) for a non-panicking version of this function. fn count_digits_radix(self, radix: Self::Radix) -> usize { match radix { 0 | 1 => panic!("base of integer logarithm must be at least 2"), @@ -882,6 +986,19 @@ macro_rules! impl_count_digits { _ => 1 + self.get().ilog(radix) as usize, } } + + #[inline(always)] + /// Returns the count of digits in an integer as interpreted with the given [radix](https://en.wikipedia.org/wiki/Radix). + /// + /// Returns [None] if the provided radix is 0 or 1. + /// + /// See [count_digits_radix()](CountDigits::count_digits_radix) for a panicking version of this function. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option { + match radix { + 0 | 1 => None, + radix => Some(self.count_digits_radix(radix)), + } + } } }; } @@ -889,25 +1006,41 @@ macro_rules! impl_count_digits { impl CountDigits for &T { type Radix = ::Radix; + #[inline(always)] + /// Calls [count_bits()][CountDigits::count_bits] on the inner value. fn count_bits(self) -> u32 { (*self).count_bits() } + #[inline(always)] + /// Calls [count_octal_digits()][CountDigits::count_octal_digits] on the inner value. fn count_octal_digits(self) -> u32 { (*self).count_octal_digits() } + #[inline(always)] + /// Calls [count_digits()][CountDigits::count_digits] on the inner value. fn count_digits(self) -> usize { (*self).count_digits() } + #[inline(always)] + /// Calls [count_hex_digits()][CountDigits::count_hex_digits] on the inner value. fn count_hex_digits(self) -> u32 { (*self).count_hex_digits() } + #[inline(always)] + /// Calls [count_digits_radix()][CountDigits::count_digits_radix] on the inner value. fn count_digits_radix(self, radix: Self::Radix) -> usize { (*self).count_digits_radix(radix) } + + #[inline(always)] + /// Calls [checked_count_digits_radix()][CountDigits::checked_count_digits_radix] on the inner value. + fn checked_count_digits_radix(self, radix: Self::Radix) -> Option { + (*self).checked_count_digits_radix(radix) + } } impl_count_digits! { @@ -1160,14 +1293,14 @@ mod count_digits { }; ($n:expr, count_digits_radix_ordering) => { assert!([ - $n.count_digits_radix(2), - $n.count_digits_radix(3), - $n.count_digits_radix(4), - $n.count_digits_radix(5), - $n.count_digits_radix(6), - $n.count_digits_radix(7), - $n.count_digits_radix(8), - $n.count_digits_radix(9), + $n.count_digits_radix(02), + $n.count_digits_radix(03), + $n.count_digits_radix(04), + $n.count_digits_radix(05), + $n.count_digits_radix(06), + $n.count_digits_radix(07), + $n.count_digits_radix(08), + $n.count_digits_radix(09), $n.count_digits_radix(11), $n.count_digits_radix(12), $n.count_digits_radix(13), @@ -1178,6 +1311,26 @@ mod count_digits { .windows(2) .all(|window| window[0] >= window[1])); }; + ($n:expr, checked_count_digits_radix_ordering) => { + assert!([ + $n.checked_count_digits_radix(02).unwrap(), + $n.checked_count_digits_radix(03).unwrap(), + $n.checked_count_digits_radix(04).unwrap(), + $n.checked_count_digits_radix(05).unwrap(), + $n.checked_count_digits_radix(06).unwrap(), + $n.checked_count_digits_radix(07).unwrap(), + $n.checked_count_digits_radix(08).unwrap(), + $n.checked_count_digits_radix(09).unwrap(), + $n.checked_count_digits_radix(11).unwrap(), + $n.checked_count_digits_radix(12).unwrap(), + $n.checked_count_digits_radix(13).unwrap(), + $n.checked_count_digits_radix(14).unwrap(), + $n.checked_count_digits_radix(15).unwrap(), + $n.checked_count_digits_radix(16).unwrap(), + ] + .windows(2) + .all(|window| window[0] >= window[1])); + }; } macro_rules! lower_bound { @@ -1338,6 +1491,12 @@ mod count_digits { iteration!($signage, $type, $non_zero_type, count_digits); iteration!($signage, $type, $non_zero_type, count_hex_digits); iteration!($signage, $type, $non_zero_type, count_digits_radix_ordering); + iteration!( + $signage, + $type, + $non_zero_type, + checked_count_digits_radix_ordering + ); }; (signed, $type:ty, $non_zero_type:ty, $function:ident) => { paste! { @@ -1387,7 +1546,15 @@ mod count_digits { } macro_rules! pass_by_reference { - (count_digits_radix, $type:ty, $non_zero_type:ty) => { + ($type:ty, $non_zero_type:ty) => { + pass_by_reference!($type, $non_zero_type, count_bits); + pass_by_reference!($type, $non_zero_type, count_octal_digits); + pass_by_reference!($type, $non_zero_type, count_hex_digits); + pass_by_reference!($type, $non_zero_type, count_digits); + pass_by_reference!($type, $non_zero_type, count_digits_radix); + pass_by_reference!($type, $non_zero_type, checked_count_digits_radix); + }; + ($type:ty, $non_zero_type:ty, count_digits_radix) => { paste! { #[test] fn [<$type _pass_by_reference_count_digits_radix>]() { @@ -1409,7 +1576,29 @@ mod count_digits { } } }; - ($function:ident, $type:ty, $non_zero_type:ty) => { + ($type:ty, $non_zero_type:ty, checked_count_digits_radix) => { + paste! { + #[test] + fn [<$type _pass_by_reference_checked_count_digits_radix>]() { + for radix in 2..20 { + for n in radix_boundaries!($type, radix).flatten() { + assert_eq!(CountDigits::checked_count_digits_radix(n, radix), CountDigits::checked_count_digits_radix(&n, radix)); + } + } + } + #[test] + #[allow(non_snake_case)] + fn [<$non_zero_type _pass_by_reference_checked_count_digits_radix>]() { + for radix in 2..20 { + for n in radix_boundaries!($type, radix).flatten() { + let n = $non_zero_type::new(n).unwrap(); + assert_eq!(CountDigits::checked_count_digits_radix(n, radix), CountDigits::checked_count_digits_radix(&n, radix)); + } + } + } + } + }; + ($type:ty, $non_zero_type:ty, $function:ident) => { paste! { #[test] fn [<$type _pass_by_reference_ $function>]() { @@ -1445,12 +1634,23 @@ mod count_digits { fn [<$type _invalid_radix_ $radix>]() { (1 as $type).count_digits_radix($radix); } + #[test] + fn [<$type _invalid_radix_ $radix _checked>]() { + assert!((1 as $type).checked_count_digits_radix($radix).is_none()); + } + + #[test] #[allow(non_snake_case)] #[should_panic(expected = "base of integer logarithm must be at least 2")] fn [<$non_zero_type _invalid_radix_ $radix>]() { $non_zero_type::new(1).unwrap().count_digits_radix($radix); } + #[test] + #[allow(non_snake_case)] + fn [<$non_zero_type _invalid_radix_ $radix _checked>]() { + assert!($non_zero_type::new(1).unwrap().checked_count_digits_radix($radix).is_none()); + } } }; } @@ -1490,6 +1690,17 @@ mod count_digits { ) } #[test] + fn [<$type _boundaries_for_radix_ $radix _checked>]() { + assert!( + radix_boundaries!($type, $radix) + .map(|[n, m]| (n.checked_count_digits_radix($radix), m.checked_count_digits_radix($radix))) + .zip(increasing_pairs()) + .all(|((lhs_actual, rhs_actual), (lhs_expected, rhs_expected))| { + lhs_expected == lhs_actual.unwrap() && rhs_expected == rhs_actual.unwrap() + }) + ) + } + #[test] #[allow(non_snake_case)] fn [<$non_zero_type _boundaries_for_radix_ $radix>]() { assert!( @@ -1502,6 +1713,19 @@ mod count_digits { }) ) } + #[test] + #[allow(non_snake_case)] + fn [<$non_zero_type _boundaries_for_radix_ $radix _checked>]() { + assert!( + radix_boundaries!($type, $radix) + .map(|[n, m]| (<$non_zero_type>::new(n).unwrap(), <$non_zero_type>::new(m).unwrap())) + .map(|(n, m)| (n.checked_count_digits_radix($radix), m.checked_count_digits_radix($radix))) + .zip(increasing_pairs()) + .all(|((lhs_actual, rhs_actual), (lhs_expected, rhs_expected))| { + lhs_expected == lhs_actual.unwrap() && rhs_expected == rhs_actual.unwrap() + }) + ) + } } }; } @@ -1566,68 +1790,16 @@ mod count_digits { add_test!(min_and_max, u128, NonZeroU128); add_test!(min_and_max, usize, NonZeroUsize); - add_test!(pass_by_reference, count_bits, i8, NonZeroI8); - add_test!(pass_by_reference, count_bits, i16, NonZeroI16); - add_test!(pass_by_reference, count_bits, i32, NonZeroI32); - add_test!(pass_by_reference, count_bits, i64, NonZeroI64); - add_test!(pass_by_reference, count_bits, i128, NonZeroI128); - add_test!(pass_by_reference, count_bits, isize, NonZeroIsize); - add_test!(pass_by_reference, count_bits, u8, NonZeroU8); - add_test!(pass_by_reference, count_bits, u16, NonZeroU16); - add_test!(pass_by_reference, count_bits, u32, NonZeroU32); - add_test!(pass_by_reference, count_bits, u64, NonZeroU64); - add_test!(pass_by_reference, count_bits, u128, NonZeroU128); - add_test!(pass_by_reference, count_bits, usize, NonZeroUsize); - - add_test!(pass_by_reference, count_octal_digits, i8, NonZeroI8); - add_test!(pass_by_reference, count_octal_digits, i16, NonZeroI16); - add_test!(pass_by_reference, count_octal_digits, i32, NonZeroI32); - add_test!(pass_by_reference, count_octal_digits, i64, NonZeroI64); - add_test!(pass_by_reference, count_octal_digits, i128, NonZeroI128); - add_test!(pass_by_reference, count_octal_digits, isize, NonZeroIsize); - add_test!(pass_by_reference, count_octal_digits, u8, NonZeroU8); - add_test!(pass_by_reference, count_octal_digits, u16, NonZeroU16); - add_test!(pass_by_reference, count_octal_digits, u32, NonZeroU32); - add_test!(pass_by_reference, count_octal_digits, u64, NonZeroU64); - add_test!(pass_by_reference, count_octal_digits, u128, NonZeroU128); - add_test!(pass_by_reference, count_octal_digits, usize, NonZeroUsize); - - add_test!(pass_by_reference, count_hex_digits, i8, NonZeroI8); - add_test!(pass_by_reference, count_hex_digits, i16, NonZeroI16); - add_test!(pass_by_reference, count_hex_digits, i32, NonZeroI32); - add_test!(pass_by_reference, count_hex_digits, i64, NonZeroI64); - add_test!(pass_by_reference, count_hex_digits, i128, NonZeroI128); - add_test!(pass_by_reference, count_hex_digits, isize, NonZeroIsize); - add_test!(pass_by_reference, count_hex_digits, u8, NonZeroU8); - add_test!(pass_by_reference, count_hex_digits, u16, NonZeroU16); - add_test!(pass_by_reference, count_hex_digits, u32, NonZeroU32); - add_test!(pass_by_reference, count_hex_digits, u64, NonZeroU64); - add_test!(pass_by_reference, count_hex_digits, u128, NonZeroU128); - add_test!(pass_by_reference, count_hex_digits, usize, NonZeroUsize); - - add_test!(pass_by_reference, count_digits, i8, NonZeroI8); - add_test!(pass_by_reference, count_digits, i16, NonZeroI16); - add_test!(pass_by_reference, count_digits, i32, NonZeroI32); - add_test!(pass_by_reference, count_digits, i64, NonZeroI64); - add_test!(pass_by_reference, count_digits, i128, NonZeroI128); - add_test!(pass_by_reference, count_digits, isize, NonZeroIsize); - add_test!(pass_by_reference, count_digits, u8, NonZeroU8); - add_test!(pass_by_reference, count_digits, u16, NonZeroU16); - add_test!(pass_by_reference, count_digits, u32, NonZeroU32); - add_test!(pass_by_reference, count_digits, u64, NonZeroU64); - add_test!(pass_by_reference, count_digits, u128, NonZeroU128); - add_test!(pass_by_reference, count_digits, usize, NonZeroUsize); - - add_test!(pass_by_reference, count_digits_radix, i8, NonZeroI8); - add_test!(pass_by_reference, count_digits_radix, i16, NonZeroI16); - add_test!(pass_by_reference, count_digits_radix, i32, NonZeroI32); - add_test!(pass_by_reference, count_digits_radix, i64, NonZeroI64); - add_test!(pass_by_reference, count_digits_radix, i128, NonZeroI128); - add_test!(pass_by_reference, count_digits_radix, isize, NonZeroIsize); - add_test!(pass_by_reference, count_digits_radix, u8, NonZeroU8); - add_test!(pass_by_reference, count_digits_radix, u16, NonZeroU16); - add_test!(pass_by_reference, count_digits_radix, u32, NonZeroU32); - add_test!(pass_by_reference, count_digits_radix, u64, NonZeroU64); - add_test!(pass_by_reference, count_digits_radix, u128, NonZeroU128); - add_test!(pass_by_reference, count_digits_radix, usize, NonZeroUsize); + add_test!(pass_by_reference, i8, NonZeroI8); + add_test!(pass_by_reference, i16, NonZeroI16); + add_test!(pass_by_reference, i32, NonZeroI32); + add_test!(pass_by_reference, i64, NonZeroI64); + add_test!(pass_by_reference, i128, NonZeroI128); + add_test!(pass_by_reference, isize, NonZeroIsize); + add_test!(pass_by_reference, u8, NonZeroU8); + add_test!(pass_by_reference, u16, NonZeroU16); + add_test!(pass_by_reference, u32, NonZeroU32); + add_test!(pass_by_reference, u64, NonZeroU64); + add_test!(pass_by_reference, u128, NonZeroU128); + add_test!(pass_by_reference, usize, NonZeroUsize); }