@@ -1154,22 +1154,32 @@ pub enum Parity {
11541154}
11551155
11561156impl 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.
11581160 pub fn to_u8 ( self ) -> u8 {
11591161 self as u8
11601162 }
11611163
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.
11631167 pub fn to_i32 ( self ) -> i32 {
11641168 self as i32
11651169 }
11661170
11671171 /// 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.
11681175 pub fn from_u8 ( parity : u8 ) -> Result < Parity , Error > {
1169- Parity :: from_i32 ( parity as i32 )
1176+ Parity :: from_i32 ( parity. into ( ) )
11701177 }
11711178
11721179 /// 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.
11731183 pub fn from_i32 ( parity : i32 ) -> Result < Parity , Error > {
11741184 match parity {
11751185 0 => Ok ( Parity :: Even ) ,
@@ -1181,7 +1191,9 @@ impl Parity {
11811191
11821192impl From < i32 > for Parity {
11831193 /// 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.
11851197 fn from ( parity : i32 ) -> Parity {
11861198 if parity % 2 == 0 {
11871199 Parity :: Even
@@ -1191,12 +1203,14 @@ impl From<i32> for Parity {
11911203 }
11921204}
11931205
1206+ /// The conversion returns `0` for even parity and `1` for odd.
11941207impl From < Parity > for i32 {
11951208 fn from ( parity : Parity ) -> i32 {
11961209 parity. to_i32 ( )
11971210 }
11981211}
11991212
1213+ /// Returns even parity if the operands are equal, odd otherwise.
12001214impl BitXor for Parity {
12011215 type Output = Parity ;
12021216
@@ -1210,6 +1224,7 @@ impl BitXor for Parity {
12101224 }
12111225}
12121226
1227+ /// The parity is serialized as `i32` - `0` for even, `1` for odd.
12131228#[ cfg( feature = "serde" ) ]
12141229#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
12151230impl :: serde:: Serialize for Parity {
@@ -1218,6 +1233,7 @@ impl ::serde::Serialize for Parity {
12181233 }
12191234}
12201235
1236+ /// The parity is deserialized as `i32` - `0` for even, `1` for odd.
12211237#[ cfg( feature = "serde" ) ]
12221238#[ cfg_attr( docsrs, doc( cfg( feature = "serde" ) ) ) ]
12231239impl < ' de > :: serde:: Deserialize < ' de > for Parity {
0 commit comments