File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -99,10 +99,16 @@ pub trait ToBytes {
99
99
/// # #[cfg(not(has_int_to_from_bytes))]
100
100
/// # fn main() {}
101
101
/// ```
102
- fn to_ne_bytes ( & self ) -> Self :: Bytes ;
102
+ fn to_ne_bytes ( & self ) -> Self :: Bytes {
103
+ #[ cfg( target_endian = "big" ) ]
104
+ let bytes = self . to_be_bytes ( ) ;
105
+ #[ cfg( target_endian = "little" ) ]
106
+ let bytes = self . to_le_bytes ( ) ;
107
+ bytes
108
+ }
103
109
}
104
110
105
- pub trait FromBytes {
111
+ pub trait FromBytes : Sized {
106
112
type Bytes : NumBytes ;
107
113
108
114
/// Create a number from its representation as a byte array in big endian.
@@ -156,7 +162,13 @@ pub trait FromBytes {
156
162
/// # #[cfg(not(has_int_to_from_bytes))]
157
163
/// # fn main() {}
158
164
/// ```
159
- fn from_ne_bytes ( bytes : & Self :: Bytes ) -> Self ;
165
+ fn from_ne_bytes ( bytes : & Self :: Bytes ) -> Self {
166
+ #[ cfg( target_endian = "big" ) ]
167
+ let this = Self :: from_be_bytes ( bytes) ;
168
+ #[ cfg( target_endian = "little" ) ]
169
+ let this = Self :: from_le_bytes ( bytes) ;
170
+ this
171
+ }
160
172
}
161
173
162
174
macro_rules! float_to_from_bytes_impl {
You can’t perform that action at this time.
0 commit comments