1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::{FromAs, IntoAs};
use core::ops::Div;
#[allow(clippy::len_without_is_empty)]
pub trait IntegerLen {
fn len(self) -> usize;
}
impl<T> IntegerLen for T
where
T: Eq + Copy + Div<Output = T> + IntoAs<T> + FromAs<u8>,
u8: IntoAs<T>,
{
#[inline]
fn len(mut self) -> usize {
let mut count = 0;
let ten = 10.into_as();
let zero = <T>::from_as(0);
while self != zero {
self = self / ten;
count += 1;
}
if count == 0 {
1
} else {
count
}
}
}
pub trait TypeInfo {
fn info() -> &'static str;
}
macro_rules! type_info_impls {
($($type:ty, $type_str:expr);* ) => {
$(
impl TypeInfo for $type {
#[inline]
fn info() -> &'static str {
$type_str
}
}
)*
}
}
type_info_impls! { i8, "i8"; i16, "i16"; i32, "i32"; i64, "i64"; isize, "isize"; i128, "i128" }
type_info_impls! { u8, "u8"; u16, "u16"; u32, "u32"; u64, "u64"; usize, "usize"; u128, "u128" }
pub trait ValTypeInfo {
fn info(self) -> &'static str;
}
macro_rules! val_type_info_impls {
($($type:ty, $type_str:expr);* ) => {
$(
impl ValTypeInfo for $type {
#[inline]
fn info(self) -> &'static str {
$type_str
}
}
)*
}
}
val_type_info_impls! { i8, "i8"; i16, "i16"; i32, "i32"; i64, "i64"; isize, "isize"; i128, "i128" }
val_type_info_impls! { u8, "u8"; u16, "u16"; u32, "u32"; u64, "u64"; usize, "usize"; u128, "u128" }