From 4a022f51a9f4c649a3e8191d63bf1ba94307a527 Mon Sep 17 00:00:00 2001 From: Mark Mackey Date: Fri, 8 Dec 2023 15:41:06 -0600 Subject: [PATCH 1/2] Added missing IntoIterator trait for FixedVector --- src/fixed_vector.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/fixed_vector.rs b/src/fixed_vector.rs index bfabac6..c1463c3 100644 --- a/src/fixed_vector.rs +++ b/src/fixed_vector.rs @@ -168,6 +168,15 @@ impl<'a, T, N: Unsigned> IntoIterator for &'a FixedVector { } } +impl IntoIterator for FixedVector { + type Item = T; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.vec.into_iter() + } +} + impl tree_hash::TreeHash for FixedVector where T: tree_hash::TreeHash, From c7a818e1f2efacd57621a1099957411362c7b503 Mon Sep 17 00:00:00 2001 From: Mark Mackey Date: Mon, 11 Dec 2023 11:59:22 +0100 Subject: [PATCH 2/2] Added Iterator Test --- src/fixed_vector.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fixed_vector.rs b/src/fixed_vector.rs index c1463c3..fe0e6f9 100644 --- a/src/fixed_vector.rs +++ b/src/fixed_vector.rs @@ -405,6 +405,17 @@ mod test { assert_eq!(fixed.get(4), None); } + #[test] + fn iterator() { + let vec = vec![0, 2, 4, 6]; + let fixed: FixedVector = FixedVector::from(vec); + + // test the reference version + assert_eq!((&fixed).into_iter().sum::(), 12); + // test the owned version + assert_eq!(fixed.into_iter().sum::(), 12); + } + #[test] fn ssz_encode() { let vec: FixedVector = vec![0; 2].into();