@@ -171,45 +171,38 @@ macro_rules! float_to_from_bytes_impl {
171
171
}
172
172
}
173
173
174
- #[ cfg( all(
175
- not( feature = "has_float_to_from_bytes" ) ,
176
- feature = "has_int_to_from_bytes"
177
- ) ) ]
174
+ #[ cfg( not( feature = "has_float_to_from_bytes" ) ) ]
178
175
impl ToFromBytes for $T {
179
176
type Bytes = [ u8 ; $L] ;
180
177
181
178
#[ inline]
182
179
fn to_be_bytes( & self ) -> Self :: Bytes {
183
- <$I as ToFromBytes >:: from_ne_bytes ( & self . to_ne_bytes ( ) ) . to_be_bytes ( )
180
+ <$I as ToFromBytes >:: to_be_bytes ( & self . to_bits ( ) )
184
181
}
185
182
186
183
#[ inline]
187
184
fn to_le_bytes( & self ) -> Self :: Bytes {
188
- <$I as ToFromBytes >:: from_ne_bytes ( & self . to_ne_bytes ( ) ) . to_le_bytes ( )
185
+ <$I as ToFromBytes >:: to_le_bytes ( & self . to_bits ( ) )
189
186
}
190
187
191
188
#[ inline]
192
189
fn to_ne_bytes( & self ) -> Self :: Bytes {
193
- unsafe { transmute ( * self ) }
190
+ <$I as ToFromBytes > :: to_ne_bytes ( & self . to_bits ( ) )
194
191
}
195
192
196
193
#[ inline]
197
194
fn from_be_bytes( bytes: & Self :: Bytes ) -> Self {
198
- <Self as ToFromBytes >:: from_ne_bytes(
199
- & <$I as ToFromBytes >:: from_be_bytes( bytes) . to_ne_bytes( ) ,
200
- )
195
+ Self :: from_bits( <$I as ToFromBytes >:: from_be_bytes( & bytes) )
201
196
}
202
197
203
198
#[ inline]
204
199
fn from_le_bytes( bytes: & Self :: Bytes ) -> Self {
205
- <Self as ToFromBytes >:: from_ne_bytes(
206
- & <$I as ToFromBytes >:: from_le_bytes( bytes) . to_ne_bytes( ) ,
207
- )
200
+ Self :: from_bits( <$I as ToFromBytes >:: from_le_bytes( & bytes) )
208
201
}
209
202
210
203
#[ inline]
211
204
fn from_ne_bytes( bytes: & Self :: Bytes ) -> Self {
212
- unsafe { transmute ( * bytes) }
205
+ Self :: from_bits ( <$I as ToFromBytes > :: from_ne_bytes ( & bytes) )
213
206
}
214
207
}
215
208
} ;
@@ -356,7 +349,6 @@ mod tests {
356
349
check_to_from_bytes ! ( i128 u128 ) ;
357
350
}
358
351
359
- #[ cfg( feature = "has_float_to_from_bytes" ) ]
360
352
#[ test]
361
353
fn convert_between_float_and_bytes ( ) {
362
354
macro_rules! check_to_from_bytes {
0 commit comments