use core::num::ParseIntError;
pub trait IntOpsExt: Sized {
const ZERO: Self;
const ONE: Self;
const BITS: u8;
#[must_use]
fn checked_shl(&self, rhs: u32) -> Option<Self>;
#[must_use]
fn count_ones(&self) -> u32;
#[must_use]
fn highest_one(&self) -> Option<u32>;
#[must_use]
fn lowest_one(&self) -> Option<u32>;
fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>;
}
macro_rules! impl_uint_opt_ext {
($ty:ty) => {
impl IntOpsExt for $ty {
const ZERO: Self = 0;
const ONE: Self = 1;
#[expect(
clippy::as_conversions,
clippy::cast_possible_truncation,
reason = "supported in const context"
)]
const BITS: u8 = <$ty>::BITS as u8;
#[inline]
fn checked_shl(&self, rhs: u32) -> Option<Self> {
<$ty>::checked_shl(*self, rhs)
}
#[inline]
fn count_ones(&self) -> u32 {
<$ty>::count_ones(*self)
}
#[inline]
fn lowest_one(&self) -> Option<u32> {
<$ty>::lowest_one(*self)
}
#[inline]
fn highest_one(&self) -> Option<u32> {
<$ty>::highest_one(*self)
}
#[inline]
fn from_str_radix(src: &str, radix: u32) -> Result<Self, core::num::ParseIntError> {
<$ty>::from_str_radix(src, radix)
}
}
};
}
impl_uint_opt_ext!(u8);
impl_uint_opt_ext!(u16);
impl_uint_opt_ext!(u32);
impl_uint_opt_ext!(u64);
impl_uint_opt_ext!(u128);
impl_uint_opt_ext!(usize);
impl_uint_opt_ext!(i8);
impl_uint_opt_ext!(i16);
impl_uint_opt_ext!(i32);
impl_uint_opt_ext!(i64);
impl_uint_opt_ext!(i128);
impl_uint_opt_ext!(isize);