@@ -45,13 +45,8 @@ pub trait ToBytes {
45
45
/// ```
46
46
/// use num_traits::ToBytes;
47
47
///
48
- /// # #[cfg(has_int_to_from_bytes)]
49
- /// # fn main() {
50
- /// let bytes = 0x12345678u32.to_be_bytes();
48
+ /// let bytes = ToBytes::to_be_bytes(&0x12345678u32);
51
49
/// assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]);
52
- /// # }
53
- /// # #[cfg(not(has_int_to_from_bytes))]
54
- /// # fn main() {}
55
50
/// ```
56
51
fn to_be_bytes ( & self ) -> Self :: Bytes ;
57
52
@@ -62,13 +57,8 @@ pub trait ToBytes {
62
57
/// ```
63
58
/// use num_traits::ToBytes;
64
59
///
65
- /// # #[cfg(has_int_to_from_bytes)]
66
- /// # fn main() {
67
- /// let bytes = 0x12345678u32.to_le_bytes();
60
+ /// let bytes = ToBytes::to_le_bytes(&0x12345678u32);
68
61
/// assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]);
69
- /// # }
70
- /// # #[cfg(not(has_int_to_from_bytes))]
71
- /// # fn main() {}
72
62
/// ```
73
63
fn to_le_bytes ( & self ) -> Self :: Bytes ;
74
64
@@ -85,19 +75,14 @@ pub trait ToBytes {
85
75
/// ```
86
76
/// use num_traits::ToBytes;
87
77
///
88
- /// # #[cfg(has_int_to_from_bytes)]
89
- /// # fn main() {
90
78
/// #[cfg(target_endian = "big")]
91
79
/// let expected = [0x12, 0x34, 0x56, 0x78];
92
80
///
93
- /// #[cfg(not( target_endian = "big") )]
81
+ /// #[cfg(target_endian = "little" )]
94
82
/// let expected = [0x78, 0x56, 0x34, 0x12];
95
83
///
96
- /// let bytes = 0x12345678u32. to_ne_bytes();
84
+ /// let bytes = ToBytes:: to_ne_bytes(&0x12345678u32 );
97
85
/// assert_eq!(bytes, expected)
98
- /// # }
99
- /// # #[cfg(not(has_int_to_from_bytes))]
100
- /// # fn main() {}
101
86
/// ```
102
87
fn to_ne_bytes ( & self ) -> Self :: Bytes {
103
88
#[ cfg( target_endian = "big" ) ]
@@ -118,7 +103,7 @@ pub trait FromBytes: Sized {
118
103
/// ```
119
104
/// use num_traits::FromBytes;
120
105
///
121
- /// let value = < u32 as FromBytes> ::from_be_bytes(&[0x12, 0x34, 0x56, 0x78]);
106
+ /// let value: u32 = FromBytes::from_be_bytes(&[0x12, 0x34, 0x56, 0x78]);
122
107
/// assert_eq!(value, 0x12345678);
123
108
/// ```
124
109
fn from_be_bytes ( bytes : & Self :: Bytes ) -> Self ;
@@ -130,7 +115,7 @@ pub trait FromBytes: Sized {
130
115
/// ```
131
116
/// use num_traits::FromBytes;
132
117
///
133
- /// let value = < u32 as FromBytes> ::from_le_bytes(&[0x78, 0x56, 0x34, 0x12]);
118
+ /// let value: u32 = FromBytes::from_le_bytes(&[0x78, 0x56, 0x34, 0x12]);
134
119
/// assert_eq!(value, 0x12345678);
135
120
/// ```
136
121
fn from_le_bytes ( bytes : & Self :: Bytes ) -> Self ;
@@ -148,19 +133,14 @@ pub trait FromBytes: Sized {
148
133
/// ```
149
134
/// use num_traits::FromBytes;
150
135
///
151
- /// # #[cfg(has_int_to_from_bytes)]
152
- /// # fn main() {
153
136
/// #[cfg(target_endian = "big")]
154
137
/// let bytes = [0x12, 0x34, 0x56, 0x78];
155
138
///
156
- /// #[cfg(not( target_endian = "big") )]
139
+ /// #[cfg(target_endian = "little" )]
157
140
/// let bytes = [0x78, 0x56, 0x34, 0x12];
158
141
///
159
- /// let value = < u32 as FromBytes> ::from_ne_bytes(&bytes);
142
+ /// let value: u32 = FromBytes::from_ne_bytes(&bytes);
160
143
/// assert_eq!(value, 0x12345678)
161
- /// # }
162
- /// # #[cfg(not(has_int_to_from_bytes))]
163
- /// # fn main() {}
164
144
/// ```
165
145
fn from_ne_bytes ( bytes : & Self :: Bytes ) -> Self {
166
146
#[ cfg( target_endian = "big" ) ]
0 commit comments