Trait count_digits::CountDigits
source · pub trait CountDigits: Copy + Sized {
type Radix;
// Required methods
fn count_bits(self) -> u32;
fn count_octal_digits(self) -> u32;
fn count_digits(self) -> u32;
fn count_hex_digits(self) -> u32;
fn count_digits_radix(self, radix: Self::Radix) -> u32;
}
Expand description
A no_std trait to count the digits of an integer in various number bases.
Required Associated Types§
sourcetype Radix
type Radix
The type of integer that should be passed in to the count_digits_radix() function.
Required Methods§
sourcefn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
use count_digits::CountDigits;
assert_eq!(008, i8::MIN.count_bits());
assert_eq!(007, i8::MAX.count_bits());
assert_eq!(008, NonZeroI8::MIN.count_bits());
assert_eq!(007, NonZeroI8::MAX.count_bits());
assert_eq!(001, u8::MIN.count_bits());
assert_eq!(008, u8::MAX.count_bits());
assert_eq!(001, NonZeroU8::MIN.count_bits());
assert_eq!(008, NonZeroU8::MAX.count_bits());
assert_eq!(016, i16::MIN.count_bits());
assert_eq!(015, i16::MAX.count_bits());
assert_eq!(016, NonZeroI16::MIN.count_bits());
assert_eq!(015, NonZeroI16::MAX.count_bits());
assert_eq!(001, u16::MIN.count_bits());
assert_eq!(016, u16::MAX.count_bits());
assert_eq!(001, NonZeroU16::MIN.count_bits());
assert_eq!(016, NonZeroU16::MAX.count_bits());
assert_eq!(032, i32::MIN.count_bits());
assert_eq!(031, i32::MAX.count_bits());
assert_eq!(032, NonZeroI32::MIN.count_bits());
assert_eq!(031, NonZeroI32::MAX.count_bits());
assert_eq!(001, u32::MIN.count_bits());
assert_eq!(032, u32::MAX.count_bits());
assert_eq!(001, NonZeroU32::MIN.count_bits());
assert_eq!(032, NonZeroU32::MAX.count_bits());
assert_eq!(064, i64::MIN.count_bits());
assert_eq!(063, i64::MAX.count_bits());
assert_eq!(064, NonZeroI64::MIN.count_bits());
assert_eq!(063, NonZeroI64::MAX.count_bits());
assert_eq!(001, u64::MIN.count_bits());
assert_eq!(064, u64::MAX.count_bits());
assert_eq!(001, NonZeroU64::MIN.count_bits());
assert_eq!(064, NonZeroU64::MAX.count_bits());
assert_eq!(128, i128::MIN.count_bits());
assert_eq!(127, i128::MAX.count_bits());
assert_eq!(128, NonZeroI128::MIN.count_bits());
assert_eq!(127, NonZeroI128::MAX.count_bits());
assert_eq!(001, u128::MIN.count_bits());
assert_eq!(128, u128::MAX.count_bits());
assert_eq!(001, NonZeroU128::MIN.count_bits());
assert_eq!(128, NonZeroU128::MAX.count_bits());
#[cfg(target_pointer_width = "64")] {
assert_eq!(isize::MIN.count_bits(), i64::MIN.count_bits());
assert_eq!(isize::MAX.count_bits(), i64::MAX.count_bits());
assert_eq!(NonZeroIsize::MIN.count_bits(), NonZeroI64::MIN.count_bits());
assert_eq!(NonZeroIsize::MAX.count_bits(), NonZeroI64::MAX.count_bits());
assert_eq!(usize::MIN.count_bits(), u64::MIN.count_bits());
assert_eq!(usize::MAX.count_bits(), u64::MAX.count_bits());
assert_eq!(NonZeroUsize::MIN.count_bits(), NonZeroU64::MIN.count_bits());
assert_eq!(NonZeroUsize::MAX.count_bits(), NonZeroU64::MAX.count_bits());
}
#[cfg(target_pointer_width = "32")] {
assert_eq!(isize::MIN.count_bits(), i32::MIN.count_bits());
assert_eq!(isize::MAX.count_bits(), i32::MAX.count_bits());
assert_eq!(NonZeroIsize::MIN.count_bits(), NonZeroI32::MIN.count_bits());
assert_eq!(NonZeroIsize::MAX.count_bits(), NonZeroI32::MAX.count_bits());
assert_eq!(usize::MIN.count_bits(), u32::MIN.count_bits());
assert_eq!(usize::MAX.count_bits(), u32::MAX.count_bits());
assert_eq!(NonZeroUsize::MIN.count_bits(), NonZeroU32::MIN.count_bits());
assert_eq!(NonZeroUsize::MAX.count_bits(), NonZeroU32::MAX.count_bits());
}
#[cfg(target_pointer_width = "16")] {
assert_eq!(isize::MIN.count_bits(), i16::MIN.count_bits());
assert_eq!(isize::MAX.count_bits(), i16::MAX.count_bits());
assert_eq!(NonZeroIsize::MIN.count_bits(), NonZeroI16::MIN.count_bits());
assert_eq!(NonZeroIsize::MAX.count_bits(), NonZeroI16::MAX.count_bits());
assert_eq!(usize::MIN.count_bits(), u16::MIN.count_bits());
assert_eq!(usize::MAX.count_bits(), u16::MAX.count_bits());
assert_eq!(NonZeroUsize::MIN.count_bits(), NonZeroU16::MIN.count_bits());
assert_eq!(NonZeroUsize::MAX.count_bits(), NonZeroU16::MAX.count_bits());
}
#[cfg(target_pointer_width = "8")] {
assert_eq!(isize::MIN.count_bits(), i8::MIN.count_bits());
assert_eq!(isize::MAX.count_bits(), i8::MAX.count_bits());
assert_eq!(NonZeroIsize::MIN.count_bits(), NonZeroI8::MIN.count_bits());
assert_eq!(NonZeroIsize::MAX.count_bits(), NonZeroI8::MAX.count_bits());
assert_eq!(usize::MIN.count_bits(), u8::MIN.count_bits());
assert_eq!(usize::MAX.count_bits(), u8::MAX.count_bits());
assert_eq!(NonZeroUsize::MIN.count_bits(), NonZeroU8::MIN.count_bits());
assert_eq!(NonZeroUsize::MAX.count_bits(), NonZeroU8::MAX.count_bits());
}
sourcefn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
§Examples
use count_digits::CountDigits;
assert_eq!(03, i8::MIN.count_octal_digits());
assert_eq!(03, i8::MAX.count_octal_digits());
assert_eq!(03, NonZeroI8::MIN.count_octal_digits());
assert_eq!(03, NonZeroI8::MAX.count_octal_digits());
assert_eq!(01, u8::MIN.count_octal_digits());
assert_eq!(03, u8::MAX.count_octal_digits());
assert_eq!(01, NonZeroU8::MIN.count_octal_digits());
assert_eq!(03, NonZeroU8::MAX.count_octal_digits());
assert_eq!(06, i16::MIN.count_octal_digits());
assert_eq!(05, i16::MAX.count_octal_digits());
assert_eq!(06, NonZeroI16::MIN.count_octal_digits());
assert_eq!(05, NonZeroI16::MAX.count_octal_digits());
assert_eq!(01, u16::MIN.count_octal_digits());
assert_eq!(06, u16::MAX.count_octal_digits());
assert_eq!(01, NonZeroU16::MIN.count_octal_digits());
assert_eq!(06, NonZeroU16::MAX.count_octal_digits());
assert_eq!(11, i32::MIN.count_octal_digits());
assert_eq!(11, i32::MAX.count_octal_digits());
assert_eq!(11, NonZeroI32::MIN.count_octal_digits());
assert_eq!(11, NonZeroI32::MAX.count_octal_digits());
assert_eq!(01, u32::MIN.count_octal_digits());
assert_eq!(11, u32::MAX.count_octal_digits());
assert_eq!(01, NonZeroU32::MIN.count_octal_digits());
assert_eq!(11, NonZeroU32::MAX.count_octal_digits());
assert_eq!(22, i64::MIN.count_octal_digits());
assert_eq!(21, i64::MAX.count_octal_digits());
assert_eq!(22, NonZeroI64::MIN.count_octal_digits());
assert_eq!(21, NonZeroI64::MAX.count_octal_digits());
assert_eq!(01, u64::MIN.count_octal_digits());
assert_eq!(22, u64::MAX.count_octal_digits());
assert_eq!(01, NonZeroU64::MIN.count_octal_digits());
assert_eq!(22, NonZeroU64::MAX.count_octal_digits());
assert_eq!(43, i128::MIN.count_octal_digits());
assert_eq!(43, i128::MAX.count_octal_digits());
assert_eq!(43, NonZeroI128::MIN.count_octal_digits());
assert_eq!(43, NonZeroI128::MAX.count_octal_digits());
assert_eq!(01, u128::MIN.count_octal_digits());
assert_eq!(43, u128::MAX.count_octal_digits());
assert_eq!(01, NonZeroU128::MIN.count_octal_digits());
assert_eq!(43, NonZeroU128::MAX.count_octal_digits());
#[cfg(target_pointer_width = "64")] {
assert_eq!(isize::MIN.count_octal_digits(), i64::MIN.count_octal_digits());
assert_eq!(isize::MAX.count_octal_digits(), i64::MAX.count_octal_digits());
assert_eq!(NonZeroIsize::MIN.count_octal_digits(), NonZeroI64::MIN.count_octal_digits());
assert_eq!(NonZeroIsize::MAX.count_octal_digits(), NonZeroI64::MAX.count_octal_digits());
assert_eq!(usize::MIN.count_octal_digits(), u64::MIN.count_octal_digits());
assert_eq!(usize::MAX.count_octal_digits(), u64::MAX.count_octal_digits());
assert_eq!(NonZeroUsize::MIN.count_octal_digits(), NonZeroU64::MIN.count_octal_digits());
assert_eq!(NonZeroUsize::MAX.count_octal_digits(), NonZeroU64::MAX.count_octal_digits());
}
#[cfg(target_pointer_width = "32")] {
assert_eq!(isize::MIN.count_octal_digits(), i32::MIN.count_octal_digits());
assert_eq!(isize::MAX.count_octal_digits(), i32::MAX.count_octal_digits());
assert_eq!(NonZeroIsize::MIN.count_octal_digits(), NonZeroI32::MIN.count_octal_digits());
assert_eq!(NonZeroIsize::MAX.count_octal_digits(), NonZeroI32::MAX.count_octal_digits());
assert_eq!(usize::MIN.count_octal_digits(), u32::MIN.count_octal_digits());
assert_eq!(usize::MAX.count_octal_digits(), u32::MAX.count_octal_digits());
assert_eq!(NonZeroUsize::MIN.count_octal_digits(), NonZeroU32::MIN.count_octal_digits());
assert_eq!(NonZeroUsize::MAX.count_octal_digits(), NonZeroU32::MAX.count_octal_digits());
}
#[cfg(target_pointer_width = "16")] {
assert_eq!(isize::MIN.count_octal_digits(), i16::MIN.count_octal_digits());
assert_eq!(isize::MAX.count_octal_digits(), i16::MAX.count_octal_digits());
assert_eq!(NonZeroIsize::MIN.count_octal_digits(), NonZeroI16::MIN.count_octal_digits());
assert_eq!(NonZeroIsize::MAX.count_octal_digits(), NonZeroI16::MAX.count_octal_digits());
assert_eq!(usize::MIN.count_octal_digits(), u16::MIN.count_octal_digits());
assert_eq!(usize::MAX.count_octal_digits(), u16::MAX.count_octal_digits());
assert_eq!(NonZeroUsize::MIN.count_octal_digits(), NonZeroU16::MIN.count_octal_digits());
assert_eq!(NonZeroUsize::MAX.count_octal_digits(), NonZeroU16::MAX.count_octal_digits());
}
#[cfg(target_pointer_width = "8")] {
assert_eq!(isize::MIN.count_octal_digits(), i8::MIN.count_octal_digits());
assert_eq!(isize::MAX.count_octal_digits(), i8::MAX.count_octal_digits());
assert_eq!(NonZeroIsize::MIN.count_octal_digits(), NonZeroI8::MIN.count_octal_digits());
assert_eq!(NonZeroIsize::MAX.count_octal_digits(), NonZeroI8::MAX.count_octal_digits());
assert_eq!(usize::MIN.count_octal_digits(), u8::MIN.count_octal_digits());
assert_eq!(usize::MAX.count_octal_digits(), u8::MAX.count_octal_digits());
assert_eq!(NonZeroUsize::MIN.count_octal_digits(), NonZeroU8::MIN.count_octal_digits());
assert_eq!(NonZeroUsize::MAX.count_octal_digits(), NonZeroU8::MAX.count_octal_digits());
}
sourcefn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
§Note
Counts digits only: the negative sign for negative numbers is not counted.
§Examples
use count_digits::CountDigits;
assert_eq!(03, i8::MIN.count_digits());
assert_eq!(03, i8::MAX.count_digits());
assert_eq!(03, NonZeroI8::MIN.count_digits());
assert_eq!(03, NonZeroI8::MAX.count_digits());
assert_eq!(01, u8::MIN.count_digits());
assert_eq!(03, u8::MAX.count_digits());
assert_eq!(01, NonZeroU8::MIN.count_digits());
assert_eq!(03, NonZeroU8::MAX.count_digits());
assert_eq!(05, i16::MIN.count_digits());
assert_eq!(05, i16::MAX.count_digits());
assert_eq!(05, NonZeroI16::MIN.count_digits());
assert_eq!(05, NonZeroI16::MAX.count_digits());
assert_eq!(01, u16::MIN.count_digits());
assert_eq!(05, u16::MAX.count_digits());
assert_eq!(01, NonZeroU16::MIN.count_digits());
assert_eq!(05, NonZeroU16::MAX.count_digits());
assert_eq!(10, i32::MIN.count_digits());
assert_eq!(10, i32::MAX.count_digits());
assert_eq!(10, NonZeroI32::MIN.count_digits());
assert_eq!(10, NonZeroI32::MAX.count_digits());
assert_eq!(01, u32::MIN.count_digits());
assert_eq!(10, u32::MAX.count_digits());
assert_eq!(01, NonZeroU32::MIN.count_digits());
assert_eq!(10, NonZeroU32::MAX.count_digits());
assert_eq!(19, i64::MIN.count_digits());
assert_eq!(19, i64::MAX.count_digits());
assert_eq!(19, NonZeroI64::MIN.count_digits());
assert_eq!(19, NonZeroI64::MAX.count_digits());
assert_eq!(01, u64::MIN.count_digits());
assert_eq!(20, u64::MAX.count_digits());
assert_eq!(01, NonZeroU64::MIN.count_digits());
assert_eq!(20, NonZeroU64::MAX.count_digits());
assert_eq!(39, i128::MIN.count_digits());
assert_eq!(39, i128::MAX.count_digits());
assert_eq!(39, NonZeroI128::MIN.count_digits());
assert_eq!(39, NonZeroI128::MAX.count_digits());
assert_eq!(01, u128::MIN.count_digits());
assert_eq!(39, u128::MAX.count_digits());
assert_eq!(01, NonZeroU128::MIN.count_digits());
assert_eq!(39, NonZeroU128::MAX.count_digits());
#[cfg(target_pointer_width = "64")] {
assert_eq!(isize::MIN.count_digits(), i64::MIN.count_digits());
assert_eq!(isize::MAX.count_digits(), i64::MAX.count_digits());
assert_eq!(NonZeroIsize::MIN.count_digits(), NonZeroI64::MIN.count_digits());
assert_eq!(NonZeroIsize::MAX.count_digits(), NonZeroI64::MAX.count_digits());
assert_eq!(usize::MIN.count_digits(), u64::MIN.count_digits());
assert_eq!(usize::MAX.count_digits(), u64::MAX.count_digits());
assert_eq!(NonZeroUsize::MIN.count_digits(), NonZeroU64::MIN.count_digits());
assert_eq!(NonZeroUsize::MAX.count_digits(), NonZeroU64::MAX.count_digits());
}
#[cfg(target_pointer_width = "32")] {
assert_eq!(isize::MIN.count_digits(), i32::MIN.count_digits());
assert_eq!(isize::MAX.count_digits(), i32::MAX.count_digits());
assert_eq!(NonZeroIsize::MIN.count_digits(), NonZeroI32::MIN.count_digits());
assert_eq!(NonZeroIsize::MAX.count_digits(), NonZeroI32::MAX.count_digits());
assert_eq!(usize::MIN.count_digits(), u32::MIN.count_digits());
assert_eq!(usize::MAX.count_digits(), u32::MAX.count_digits());
assert_eq!(NonZeroUsize::MIN.count_digits(), NonZeroU32::MIN.count_digits());
assert_eq!(NonZeroUsize::MAX.count_digits(), NonZeroU32::MAX.count_digits());
}
#[cfg(target_pointer_width = "16")] {
assert_eq!(isize::MIN.count_digits(), i16::MIN.count_digits());
assert_eq!(isize::MAX.count_digits(), i16::MAX.count_digits());
assert_eq!(NonZeroIsize::MIN.count_digits(), NonZeroI16::MIN.count_digits());
assert_eq!(NonZeroIsize::MAX.count_digits(), NonZeroI16::MAX.count_digits());
assert_eq!(usize::MIN.count_digits(), u16::MIN.count_digits());
assert_eq!(usize::MAX.count_digits(), u16::MAX.count_digits());
assert_eq!(NonZeroUsize::MIN.count_digits(), NonZeroU16::MIN.count_digits());
assert_eq!(NonZeroUsize::MAX.count_digits(), NonZeroU16::MAX.count_digits());
}
#[cfg(target_pointer_width = "8")] {
assert_eq!(isize::MIN.count_digits(), i8::MIN.count_digits());
assert_eq!(isize::MAX.count_digits(), i8::MAX.count_digits());
assert_eq!(NonZeroIsize::MIN.count_digits(), NonZeroI8::MIN.count_digits());
assert_eq!(NonZeroIsize::MAX.count_digits(), NonZeroI8::MAX.count_digits());
assert_eq!(usize::MIN.count_digits(), u8::MIN.count_digits());
assert_eq!(usize::MAX.count_digits(), u8::MAX.count_digits());
assert_eq!(NonZeroUsize::MIN.count_digits(), NonZeroU8::MIN.count_digits());
assert_eq!(NonZeroUsize::MAX.count_digits(), NonZeroU8::MAX.count_digits());
}
sourcefn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
§Examples
use count_digits::CountDigits;
assert_eq!(02, i8::MIN.count_hex_digits());
assert_eq!(02, i8::MAX.count_hex_digits());
assert_eq!(02, NonZeroI8::MIN.count_hex_digits());
assert_eq!(02, NonZeroI8::MAX.count_hex_digits());
assert_eq!(01, u8::MIN.count_hex_digits());
assert_eq!(02, u8::MAX.count_hex_digits());
assert_eq!(01, NonZeroU8::MIN.count_hex_digits());
assert_eq!(02, NonZeroU8::MAX.count_hex_digits());
assert_eq!(04, i16::MIN.count_hex_digits());
assert_eq!(04, i16::MAX.count_hex_digits());
assert_eq!(04, NonZeroI16::MIN.count_hex_digits());
assert_eq!(04, NonZeroI16::MAX.count_hex_digits());
assert_eq!(01, u16::MIN.count_hex_digits());
assert_eq!(04, u16::MAX.count_hex_digits());
assert_eq!(01, NonZeroU16::MIN.count_hex_digits());
assert_eq!(04, NonZeroU16::MAX.count_hex_digits());
assert_eq!(08, i32::MIN.count_hex_digits());
assert_eq!(08, i32::MAX.count_hex_digits());
assert_eq!(08, NonZeroI32::MIN.count_hex_digits());
assert_eq!(08, NonZeroI32::MAX.count_hex_digits());
assert_eq!(01, u32::MIN.count_hex_digits());
assert_eq!(08, u32::MAX.count_hex_digits());
assert_eq!(01, NonZeroU32::MIN.count_hex_digits());
assert_eq!(08, NonZeroU32::MAX.count_hex_digits());
assert_eq!(16, i64::MIN.count_hex_digits());
assert_eq!(16, i64::MAX.count_hex_digits());
assert_eq!(16, NonZeroI64::MIN.count_hex_digits());
assert_eq!(16, NonZeroI64::MAX.count_hex_digits());
assert_eq!(01, u64::MIN.count_hex_digits());
assert_eq!(16, u64::MAX.count_hex_digits());
assert_eq!(01, NonZeroU64::MIN.count_hex_digits());
assert_eq!(16, NonZeroU64::MAX.count_hex_digits());
assert_eq!(32, i128::MIN.count_hex_digits());
assert_eq!(32, i128::MAX.count_hex_digits());
assert_eq!(32, NonZeroI128::MIN.count_hex_digits());
assert_eq!(32, NonZeroI128::MAX.count_hex_digits());
assert_eq!(01, u128::MIN.count_hex_digits());
assert_eq!(32, u128::MAX.count_hex_digits());
assert_eq!(01, NonZeroU128::MIN.count_hex_digits());
assert_eq!(32, NonZeroU128::MAX.count_hex_digits());
#[cfg(target_pointer_width = "64")] {
assert_eq!(isize::MIN.count_hex_digits(), i64::MIN.count_hex_digits());
assert_eq!(isize::MAX.count_hex_digits(), i64::MAX.count_hex_digits());
assert_eq!(NonZeroIsize::MIN.count_hex_digits(), NonZeroI64::MIN.count_hex_digits());
assert_eq!(NonZeroIsize::MAX.count_hex_digits(), NonZeroI64::MAX.count_hex_digits());
assert_eq!(usize::MIN.count_hex_digits(), u64::MIN.count_hex_digits());
assert_eq!(usize::MAX.count_hex_digits(), u64::MAX.count_hex_digits());
assert_eq!(NonZeroUsize::MIN.count_hex_digits(), NonZeroU64::MIN.count_hex_digits());
assert_eq!(NonZeroUsize::MAX.count_hex_digits(), NonZeroU64::MAX.count_hex_digits());
}
#[cfg(target_pointer_width = "32")] {
assert_eq!(isize::MIN.count_hex_digits(), i32::MIN.count_hex_digits());
assert_eq!(isize::MAX.count_hex_digits(), i32::MAX.count_hex_digits());
assert_eq!(NonZeroIsize::MIN.count_hex_digits(), NonZeroI32::MIN.count_hex_digits());
assert_eq!(NonZeroIsize::MAX.count_hex_digits(), NonZeroI32::MAX.count_hex_digits());
assert_eq!(usize::MIN.count_hex_digits(), u32::MIN.count_hex_digits());
assert_eq!(usize::MAX.count_hex_digits(), u32::MAX.count_hex_digits());
assert_eq!(NonZeroUsize::MIN.count_hex_digits(), NonZeroU32::MIN.count_hex_digits());
assert_eq!(NonZeroUsize::MAX.count_hex_digits(), NonZeroU32::MAX.count_hex_digits());
}
#[cfg(target_pointer_width = "16")] {
assert_eq!(isize::MIN.count_hex_digits(), i16::MIN.count_hex_digits());
assert_eq!(isize::MAX.count_hex_digits(), i16::MAX.count_hex_digits());
assert_eq!(NonZeroIsize::MIN.count_hex_digits(), NonZeroI16::MIN.count_hex_digits());
assert_eq!(NonZeroIsize::MAX.count_hex_digits(), NonZeroI16::MAX.count_hex_digits());
assert_eq!(usize::MIN.count_hex_digits(), u16::MIN.count_hex_digits());
assert_eq!(usize::MAX.count_hex_digits(), u16::MAX.count_hex_digits());
assert_eq!(NonZeroUsize::MIN.count_hex_digits(), NonZeroU16::MIN.count_hex_digits());
assert_eq!(NonZeroUsize::MAX.count_hex_digits(), NonZeroU16::MAX.count_hex_digits());
}
#[cfg(target_pointer_width = "8")] {
assert_eq!(isize::MIN.count_hex_digits(), i8::MIN.count_hex_digits());
assert_eq!(isize::MAX.count_hex_digits(), i8::MAX.count_hex_digits());
assert_eq!(NonZeroIsize::MIN.count_hex_digits(), NonZeroI8::MIN.count_hex_digits());
assert_eq!(NonZeroIsize::MAX.count_hex_digits(), NonZeroI8::MAX.count_hex_digits());
assert_eq!(usize::MIN.count_hex_digits(), u8::MIN.count_hex_digits());
assert_eq!(usize::MAX.count_hex_digits(), u8::MAX.count_hex_digits());
assert_eq!(NonZeroUsize::MIN.count_hex_digits(), NonZeroU8::MIN.count_hex_digits());
assert_eq!(NonZeroUsize::MAX.count_hex_digits(), NonZeroU8::MAX.count_hex_digits());
}
sourcefn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
§Examples
use count_digits::CountDigits;
for n in 0..1_000_000 {
assert_eq!(n.count_digits_radix(02_u32), n.count_bits());
assert_eq!(n.count_digits_radix(08_u32), n.count_octal_digits());
assert_eq!(n.count_digits_radix(10_u32), n.count_digits());
assert_eq!(n.count_digits_radix(16_u32), n.count_hex_digits());
}
Object Safety§
Implementations on Foreign Types§
source§impl CountDigits for i8
impl CountDigits for i8
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u8
source§impl CountDigits for i16
impl CountDigits for i16
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u16
source§impl CountDigits for i32
impl CountDigits for i32
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u32
source§impl CountDigits for i64
impl CountDigits for i64
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u64
source§impl CountDigits for i128
impl CountDigits for i128
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u128
source§impl CountDigits for isize
impl CountDigits for isize
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = usize
source§impl CountDigits for u8
impl CountDigits for u8
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u8
source§impl CountDigits for u16
impl CountDigits for u16
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u16
source§impl CountDigits for u32
impl CountDigits for u32
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u32
source§impl CountDigits for u64
impl CountDigits for u64
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u64
source§impl CountDigits for u128
impl CountDigits for u128
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u128
source§impl CountDigits for usize
impl CountDigits for usize
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = usize
source§impl CountDigits for NonZeroI8
impl CountDigits for NonZeroI8
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u8
source§impl CountDigits for NonZeroI16
impl CountDigits for NonZeroI16
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u16
source§impl CountDigits for NonZeroI32
impl CountDigits for NonZeroI32
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u32
source§impl CountDigits for NonZeroI64
impl CountDigits for NonZeroI64
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u64
source§impl CountDigits for NonZeroI128
impl CountDigits for NonZeroI128
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u128
source§impl CountDigits for NonZeroIsize
impl CountDigits for NonZeroIsize
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = usize
source§impl CountDigits for NonZeroU8
impl CountDigits for NonZeroU8
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u8
source§impl CountDigits for NonZeroU16
impl CountDigits for NonZeroU16
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u16
source§impl CountDigits for NonZeroU32
impl CountDigits for NonZeroU32
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u32
source§impl CountDigits for NonZeroU64
impl CountDigits for NonZeroU64
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u64
source§impl CountDigits for NonZeroU128
impl CountDigits for NonZeroU128
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.
type Radix = u128
source§impl CountDigits for NonZeroUsize
impl CountDigits for NonZeroUsize
source§fn count_bits(self) -> u32
fn count_bits(self) -> u32
Returns the count of bits in an integer starting with the first non-zero bit.
source§fn count_digits(self) -> u32
fn count_digits(self) -> u32
Returns the count of decimal digits in an integer.
source§fn count_octal_digits(self) -> u32
fn count_octal_digits(self) -> u32
Returns the count of octal digits in an integer starting with the first non-zero digit.
source§fn count_hex_digits(self) -> u32
fn count_hex_digits(self) -> u32
Returns the count of hexadecimal digits in an integer starting with the first non-zero digit.
source§fn count_digits_radix(self, radix: Self::Radix) -> u32
fn count_digits_radix(self, radix: Self::Radix) -> u32
Returns the count of digits in an integer as interpreted with the given radix.