@@ -1201,22 +1201,32 @@ pub enum Parity {
1201
1201
}
1202
1202
1203
1203
impl Parity {
1204
- /// Converts parity into a integer (byte) value.
1204
+ /// Converts parity into an integer (byte) value.
1205
+ ///
1206
+ /// This returns `0` for even parity and `1` for odd parity.
1205
1207
pub fn to_u8 ( self ) -> u8 {
1206
1208
self as u8
1207
1209
}
1208
1210
1209
- /// Converts parity into a integer value.
1211
+ /// Converts parity into an integer value.
1212
+ ///
1213
+ /// This returns `0` for even parity and `1` for odd parity.
1210
1214
pub fn to_i32 ( self ) -> i32 {
1211
1215
self as i32
1212
1216
}
1213
1217
1214
1218
/// Constructs a [`Parity`] from a byte.
1219
+ ///
1220
+ /// The only allowed values are `0` meaning even parity and `1` meaning odd.
1221
+ /// Other values result in error being returned.
1215
1222
pub fn from_u8 ( parity : u8 ) -> Result < Parity , Error > {
1216
- Parity :: from_i32 ( parity as i32 )
1223
+ Parity :: from_i32 ( parity. into ( ) )
1217
1224
}
1218
1225
1219
1226
/// Constructs a [`Parity`] from a signed integer.
1227
+ ///
1228
+ /// The only allowed values are `0` meaning even parity and `1` meaning odd.
1229
+ /// Other values result in error being returned.
1220
1230
pub fn from_i32 ( parity : i32 ) -> Result < Parity , Error > {
1221
1231
match parity {
1222
1232
0 => Ok ( Parity :: Even ) ,
@@ -1228,7 +1238,9 @@ impl Parity {
1228
1238
1229
1239
impl From < i32 > for Parity {
1230
1240
/// Please note, this method is deprecated and will be removed in an upcoming release, it
1231
- /// is not equivalent to `from_u32()`, it is better to use `Parity::from_u32`.
1241
+ /// is **not** equivalent to `from_u32()`, it is better to use `Parity::from_u32`.
1242
+ ///
1243
+ /// This method returns same parity as the parity of input integer.
1232
1244
fn from ( parity : i32 ) -> Parity {
1233
1245
if parity % 2 == 0 {
1234
1246
Parity :: Even
@@ -1238,12 +1250,14 @@ impl From<i32> for Parity {
1238
1250
}
1239
1251
}
1240
1252
1253
+ /// The conversion returns `0` for even parity and `1` for odd.
1241
1254
impl From < Parity > for i32 {
1242
1255
fn from ( parity : Parity ) -> i32 {
1243
1256
parity. to_i32 ( )
1244
1257
}
1245
1258
}
1246
1259
1260
+ /// Returns even parity if the operands are equal, odd otherwise.
1247
1261
impl BitXor for Parity {
1248
1262
type Output = Parity ;
1249
1263
@@ -1257,6 +1271,7 @@ impl BitXor for Parity {
1257
1271
}
1258
1272
}
1259
1273
1274
+ /// The parity is serialized as `i32` - `0` for even, `1` for odd.
1260
1275
#[ cfg( feature = "serde" ) ]
1261
1276
#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
1262
1277
impl :: serde:: Serialize for Parity {
@@ -1265,6 +1280,7 @@ impl ::serde::Serialize for Parity {
1265
1280
}
1266
1281
}
1267
1282
1283
+ /// The parity is deserialized as `i32` - `0` for even, `1` for odd.
1268
1284
#[ cfg( feature = "serde" ) ]
1269
1285
#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
1270
1286
impl < ' de > :: serde:: Deserialize < ' de > for Parity {
0 commit comments