@@ -1154,22 +1154,32 @@ pub enum Parity {
1154
1154
}
1155
1155
1156
1156
impl Parity {
1157
- /// Converts parity into a integer (byte) value.
1157
+ /// Converts parity into an integer (byte) value.
1158
+ ///
1159
+ /// This returns `0` for even parity and `1` for odd parity.
1158
1160
pub fn to_u8 ( self ) -> u8 {
1159
1161
self as u8
1160
1162
}
1161
1163
1162
- /// Converts parity into a integer value.
1164
+ /// Converts parity into an integer value.
1165
+ ///
1166
+ /// This returns `0` for even parity and `1` for odd parity.
1163
1167
pub fn to_i32 ( self ) -> i32 {
1164
1168
self as i32
1165
1169
}
1166
1170
1167
1171
/// Constructs a [`Parity`] from a byte.
1172
+ ///
1173
+ /// The only allowed values are `0` meaning even parity and `1` meaning odd.
1174
+ /// Other values result in error being returned.
1168
1175
pub fn from_u8 ( parity : u8 ) -> Result < Parity , Error > {
1169
- Parity :: from_i32 ( parity as i32 )
1176
+ Parity :: from_i32 ( parity. into ( ) )
1170
1177
}
1171
1178
1172
1179
/// Constructs a [`Parity`] from a signed integer.
1180
+ ///
1181
+ /// The only allowed values are `0` meaning even parity and `1` meaning odd.
1182
+ /// Other values result in error being returned.
1173
1183
pub fn from_i32 ( parity : i32 ) -> Result < Parity , Error > {
1174
1184
match parity {
1175
1185
0 => Ok ( Parity :: Even ) ,
@@ -1181,7 +1191,9 @@ impl Parity {
1181
1191
1182
1192
impl From < i32 > for Parity {
1183
1193
/// Please note, this method is deprecated and will be removed in an upcoming release, it
1184
- /// is not equivalent to `from_u32()`, it is better to use `Parity::from_u32`.
1194
+ /// is **not** equivalent to `from_u32()`, it is better to use `Parity::from_u32`.
1195
+ ///
1196
+ /// This method returns same parity as the parity of input integer.
1185
1197
fn from ( parity : i32 ) -> Parity {
1186
1198
if parity % 2 == 0 {
1187
1199
Parity :: Even
@@ -1191,12 +1203,14 @@ impl From<i32> for Parity {
1191
1203
}
1192
1204
}
1193
1205
1206
+ /// The conversion returns `0` for even parity and `1` for odd.
1194
1207
impl From < Parity > for i32 {
1195
1208
fn from ( parity : Parity ) -> i32 {
1196
1209
parity. to_i32 ( )
1197
1210
}
1198
1211
}
1199
1212
1213
+ /// Returns even parity if the operands are equal, odd otherwise.
1200
1214
impl BitXor for Parity {
1201
1215
type Output = Parity ;
1202
1216
@@ -1210,6 +1224,7 @@ impl BitXor for Parity {
1210
1224
}
1211
1225
}
1212
1226
1227
+ /// The parity is serialized as `i32` - `0` for even, `1` for odd.
1213
1228
#[ cfg( feature = "serde" ) ]
1214
1229
#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
1215
1230
impl :: serde:: Serialize for Parity {
@@ -1218,6 +1233,7 @@ impl ::serde::Serialize for Parity {
1218
1233
}
1219
1234
}
1220
1235
1236
+ /// The parity is deserialized as `i32` - `0` for even, `1` for odd.
1221
1237
#[ cfg( feature = "serde" ) ]
1222
1238
#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
1223
1239
impl < ' de > :: serde:: Deserialize < ' de > for Parity {
0 commit comments