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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#[macro_use]
extern crate proc_macro_hack;

//To u8
proc_macro_expr_impl! {
    pub fn noprefix_hex_length_1_into_u8_impl(input: &str) -> String {
        format!("0x{}u8", input)
    }

    pub fn noprefix_hex_length_2_into_u8_impl(input: &str) -> String {
        format!("0x{}u8", input)
    }

}

//To u16
proc_macro_expr_impl! {

    pub fn noprefix_hex_length_1_into_u16_impl(input: &str) -> String {
        format!("0x{}u16", input)
    }

    pub fn noprefix_hex_length_2_into_u16_impl(input: &str) -> String {
        format!("0x{}u16", input)
    }

    pub fn noprefix_hex_length_3_into_u16_impl(input: &str) -> String {
        format!("0x{}u16", input)
    }

    pub fn noprefix_hex_length_4_into_u16_impl(input: &str) -> String {
        format!("0x{}u16", input)
    }

}

//To u32
proc_macro_expr_impl! {

    pub fn noprefix_hex_length_1_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_2_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_3_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_4_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_5_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_6_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_7_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }

    pub fn noprefix_hex_length_8_into_u32_impl(input: &str) -> String {
        format!("0x{}u32", input)
    }
}

//To u64
proc_macro_expr_impl! {
    pub fn noprefix_hex_length_1_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_2_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_3_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_4_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_5_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_6_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_7_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_8_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_9_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_10_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_11_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_12_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_13_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_14_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_15_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }

    pub fn noprefix_hex_length_16_into_u64_impl(input: &str) -> String {
        format!("0x{}u64", input)
    }
}

//Length 4
proc_macro_expr_impl!{
    // xxxx -> (u8, u8)
    pub fn noprefix_hex_length_4_into_tuple_u8_u8_impl(input: &str) -> String {
        format!("(0x{}u8, 0x{}u8)", &input[0..2], &input[2..4])
    }

}

//Length 12
proc_macro_expr_impl!{
    // xxxxxxxxxxxx -> [u8;6]
    pub fn noprefix_hex_length_12_into_array_u8_6_impl(input: &str) -> String {
        format!("[0x{}u8, 0x{}u8, 0x{}u8, 0x{}u8, 0x{}u8, 0x{}u8]", 
            &input[0..2], &input[2..4], &input[4..6], &input[6..8], &input[8..10], &input[10..12])
    }
}