1pub trait IsDigit {
19 fn is_dec_digit(&self) -> bool;
20}
21
22macro_rules! prim_impl {
23 ($($t:ty)*) => {
24 $(
25 impl IsDigit for $t {
26 fn is_dec_digit(&self) -> bool {
27 *self >= '0' as $t && *self <= '9' as $t
28 }
29 }
30 )*
31 };
32}
33
34prim_impl!(char);
35
36macro_rules! adapt_impl {
37 ($($t:ty)*) => {
38 $(
39 impl IsDigit for $t {
40 fn is_dec_digit(&self) -> bool {
41 self.as_char().unwrap().is_dec_digit()
42 }
43 }
44 )*
45 };
46}
47
48adapt_impl!(&str String);
49
50pub trait AsChar {
51 fn as_char(&self) -> Option<char>;
52}
53
54impl AsChar for &str {
55 fn as_char(&self) -> Option<char> {
56 if self.len() == 1 {
57 self.chars().next()
58 } else {
59 None
60 }
61 }
62}
63
64impl AsChar for String {
65 fn as_char(&self) -> Option<char> {
66 if self.len() == 1 {
67 self.chars().next()
68 } else {
69 None
70 }
71 }
72}