Resolve issues raised from @michaelsproul review

This commit is contained in:
Paul Hauner 2019-07-11 12:45:34 +10:00
parent 2c1afcc2d6
commit 61406b34bc
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 3 additions and 9 deletions

View File

@ -347,7 +347,7 @@ impl<T: BitfieldBehaviour> Bitfield<T> {
/// 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<Variable<N>> {
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<Fixed<N>> {
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)))

View File

@ -50,8 +50,8 @@ pub struct FixedVector<T, N> {
}
impl<T, N: Unsigned> FixedVector<T, N> {
/// 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<T>) -> Result<Self, Error> {
if vec.len() == Self::capacity() {
Ok(Self {