Trait num_convert::IntoAs
source · pub trait IntoAs<T> {
// Required method
fn into_as(self) -> T;
}Expand description
The IntoAs trait for convert into value between integer types with overflow.
Usage:
fn primitive_type_len<T>(mut num: T) -> usize
where
T: Eq + Copy + Div<Output = T> + IntoAs<T>,
u8: IntoAs<T>,
{
let mut count = 0;
// There will never be a conversion error here.
let ten = 10u8.into_as();
// There will never be a conversion error here.
let zero = 0u8.into_as();
while num != zero {
num = num / ten;
count += 1;
}
if count == 0 {
1
} else {
count
}
}