Skip to content

Commit

Permalink
Merge branch 'main' into stable-container
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson authored May 30, 2024
2 parents c128011 + e22576e commit 0e10833
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
20 changes: 20 additions & 0 deletions src/fixed_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ impl<'a, T, N: Unsigned> IntoIterator for &'a FixedVector<T, N> {
}
}

impl<T, N: Unsigned> IntoIterator for FixedVector<T, N> {
type Item = T;
type IntoIter = std::vec::IntoIter<T>;

fn into_iter(self) -> Self::IntoIter {
self.vec.into_iter()
}
}

impl<T, N: Unsigned> tree_hash::TreeHash for FixedVector<T, N>
where
T: tree_hash::TreeHash,
Expand Down Expand Up @@ -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<u64, U4> = FixedVector::from(vec);

// test the reference version
assert_eq!((&fixed).into_iter().sum::<u64>(), 12);
// test the owned version
assert_eq!(fixed.into_iter().sum::<u64>(), 12);
}

#[test]
fn ssz_encode() {
let vec: FixedVector<u16, U2> = vec![0; 2].into();
Expand Down

0 comments on commit 0e10833

Please sign in to comment.