@@ -31,7 +31,19 @@ macro_rules! fmt_impls {
31
31
}
32
32
33
33
macro_rules! convert_impls {
34
- ( $type: ident, $t8: ident, $t16: ident, $t32: ident, $t64: ident, $t128: ident, $ot8: ident, $ot16: ident, $ot32: ident) => {
34
+ (
35
+ $type: ident,
36
+ $t8: ident,
37
+ $t16: ident,
38
+ $t32: ident,
39
+ $t64: ident,
40
+ $t128: ident,
41
+ $tsize: ident,
42
+ $ot8: ident,
43
+ $ot16: ident,
44
+ $ot32: ident,
45
+ $otsize: ident
46
+ ) => {
35
47
impl :: core:: convert:: From <$t8> for $type {
36
48
fn from( val: $t8) -> Self {
37
49
Self ( $t64:: from( val) )
@@ -68,6 +80,26 @@ macro_rules! convert_impls {
68
80
}
69
81
}
70
82
83
+ impl :: core:: convert:: TryFrom <$tsize> for $type {
84
+ type Error = crate :: error:: TryFromIntError ;
85
+
86
+ fn try_from( val: $tsize) -> Result <Self , crate :: error:: TryFromIntError > {
87
+ $t64:: try_from( val)
88
+ . map_err( |_| crate :: error:: TryFromIntError :: new( ) )
89
+ . and_then( $type:: try_from)
90
+ }
91
+ }
92
+
93
+ impl :: core:: convert:: TryFrom <$otsize> for $type {
94
+ type Error = crate :: error:: TryFromIntError ;
95
+
96
+ fn try_from( val: $otsize) -> Result <Self , crate :: error:: TryFromIntError > {
97
+ $t64:: try_from( val)
98
+ . map_err( |_| crate :: error:: TryFromIntError :: new( ) )
99
+ . and_then( $type:: try_from)
100
+ }
101
+ }
102
+
71
103
impl :: core:: convert:: TryFrom <$type> for $t8 {
72
104
type Error = :: core:: num:: TryFromIntError ;
73
105
@@ -128,6 +160,22 @@ macro_rules! convert_impls {
128
160
}
129
161
}
130
162
163
+ impl :: core:: convert:: TryFrom <$type> for $tsize {
164
+ type Error = :: core:: num:: TryFromIntError ;
165
+
166
+ fn try_from( val: $type) -> Result <Self , :: core:: num:: TryFromIntError > {
167
+ Self :: try_from( val. 0 )
168
+ }
169
+ }
170
+
171
+ impl :: core:: convert:: TryFrom <$type> for $otsize {
172
+ type Error = :: core:: num:: TryFromIntError ;
173
+
174
+ fn try_from( val: $type) -> Result <Self , :: core:: num:: TryFromIntError > {
175
+ Self :: try_from( val. 0 )
176
+ }
177
+ }
178
+
131
179
impl :: core:: convert:: From <$type> for f64 {
132
180
fn from( val: $type) -> Self {
133
181
val. 0 as f64
0 commit comments