From 61406b34bc8a7fc259f6b360452a82efe34c760e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 11 Jul 2019 12:45:34 +1000 Subject: [PATCH] Resolve issues raised from @michaelsproul review --- eth2/utils/ssz_types/src/bitfield.rs | 8 +------- eth2/utils/ssz_types/src/fixed_vector.rs | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/eth2/utils/ssz_types/src/bitfield.rs b/eth2/utils/ssz_types/src/bitfield.rs index 23231e09d..6af82b48d 100644 --- a/eth2/utils/ssz_types/src/bitfield.rs +++ b/eth2/utils/ssz_types/src/bitfield.rs @@ -347,7 +347,7 @@ impl Bitfield { /// Returns true if no bits are set. pub fn is_zero(&self) -> bool { - !self.bytes.iter().any(|byte| (*byte & u8::max_value()) > 0) + self.bytes.iter().all(|byte| *byte == 0) } /// Compute the intersection (binary-and) of this bitfield with another. @@ -517,9 +517,6 @@ impl<'de, N: Unsigned + Clone> Deserialize<'de> for Bitfield> { where D: Deserializer<'de>, { - // We reverse the bit-order so that the BitVec library can read its 0th - // bit from the end of the hex string, e.g. - // "0xef01" => [0xef, 0x01] => [0b1000_0000, 0b1111_1110] let bytes = deserializer.deserialize_str(PrefixedHexVisitor)?; Self::from_ssz_bytes(&bytes) .map_err(|e| serde::de::Error::custom(format!("Bitfield {:?}", e))) @@ -542,9 +539,6 @@ impl<'de, N: Unsigned + Clone> Deserialize<'de> for Bitfield> { where D: Deserializer<'de>, { - // We reverse the bit-order so that the BitVec library can read its 0th - // bit from the end of the hex string, e.g. - // "0xef01" => [0xef, 0x01] => [0b1000_0000, 0b1111_1110] let bytes = deserializer.deserialize_str(PrefixedHexVisitor)?; Self::from_ssz_bytes(&bytes) .map_err(|e| serde::de::Error::custom(format!("Bitfield {:?}", e))) diff --git a/eth2/utils/ssz_types/src/fixed_vector.rs b/eth2/utils/ssz_types/src/fixed_vector.rs index b5d422760..8d7c2264e 100644 --- a/eth2/utils/ssz_types/src/fixed_vector.rs +++ b/eth2/utils/ssz_types/src/fixed_vector.rs @@ -50,8 +50,8 @@ pub struct FixedVector { } impl FixedVector { - /// Returns `Some` if the given `vec` equals the fixed length of `Self`. Otherwise returns - /// `None`. + /// Returns `Ok` if the given `vec` equals the fixed length of `Self`. Otherwise returns + /// `Err`. pub fn new(vec: Vec) -> Result { if vec.len() == Self::capacity() { Ok(Self {