diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 27792ae..fa7e154 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -31,3 +31,18 @@ jobs: run: rustup update stable - name: Run tests run: cargo test --release + coverage: + name: cargo-tarpaulin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get latest version of stable Rust + run: rustup update stable + - name: Install cargo-tarpaulin + uses: taiki-e/install-action@cargo-tarpaulin + - name: Check code coverage with cargo-tarpaulin + run: cargo-tarpaulin --workspace --all-features --out xml + - name: Upload to codecov.io + uses: codecov/codecov-action@v2 + with: + fail_ci_if_error: true diff --git a/Cargo.toml b/Cargo.toml index 86cf94e..f9e52ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ssz_types" -version = "0.5.4" +version = "0.6.0" edition = "2021" description = "List, vector and bitfield types for SSZ" license = "Apache-2.0" diff --git a/src/fixed_vector.rs b/src/fixed_vector.rs index b68f6d0..e9e0497 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, @@ -396,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();