use std::any::Any;
use crate::counter::{IntoCounter, ItemsCount};
pub type MaxCountUInt = condtype::num::Usize64;
pub trait CountUInt: Copy + Any {
fn into_max_uint(self) -> MaxCountUInt;
}
pub trait AsCountUInt {
fn as_max_uint(&self) -> MaxCountUInt;
}
impl<T: AsCountUInt> AsCountUInt for &T {
#[inline]
fn as_max_uint(&self) -> MaxCountUInt {
T::as_max_uint(self)
}
}
macro_rules! impl_uint {
($($i:ty),+) => {
$(impl CountUInt for $i {
#[inline]
fn into_max_uint(self) -> MaxCountUInt {
self as _
}
})+
$(impl AsCountUInt for $i {
#[inline]
fn as_max_uint(&self) -> MaxCountUInt {
*self as _
}
})+
$(impl IntoCounter for $i {
type Counter = ItemsCount;
#[inline]
fn into_counter(self) -> ItemsCount {
ItemsCount::new(self)
}
})+
};
}
impl_uint!(u8, u16, u32, u64, usize);