Skip to content

Commit

Permalink
Abstract over UpdateMap more completely
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Oct 25, 2024
1 parent b13b9e3 commit 7b42785
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ impl<T: Value, N: Unsigned, U: UpdateMap<T>> List<T, N, U> {
}
}

impl<T: Value, N: Unsigned> Default for List<T, N> {
impl<T: Value, N: Unsigned, U: UpdateMap<T>> Default for List<T, N, U> {
fn default() -> Self {
Self::empty()
}
}

impl<T: Value + Send + Sync, N: Unsigned> TreeHash for List<T, N> {
impl<T: Value + Send + Sync, N: Unsigned, U: UpdateMap<T>> TreeHash for List<T, N, U> {
fn tree_hash_type() -> tree_hash::TreeHashType {
tree_hash::TreeHashType::List
}
Expand Down Expand Up @@ -404,7 +404,7 @@ where
}

// FIXME: duplicated from `ssz::encode::impl_for_vec`
impl<T: Value, N: Unsigned> Encode for List<T, N> {
impl<T: Value, N: Unsigned, U: UpdateMap<T>> Encode for List<T, N, U> {
fn is_ssz_fixed_len() -> bool {
false
}
Expand Down Expand Up @@ -438,10 +438,11 @@ impl<T: Value, N: Unsigned> Encode for List<T, N> {
}
}

impl<T, N> TryFromIter<T> for List<T, N>
impl<T, N, U> TryFromIter<T> for List<T, N, U>
where
T: Value,
N: Unsigned,
U: UpdateMap<T>,
{
type Error = Error;

Expand All @@ -453,10 +454,11 @@ where
}
}

impl<T, N> Decode for List<T, N>
impl<T, N, U> Decode for List<T, N, U>
where
T: Value,
N: Unsigned,
U: UpdateMap<T>,
{
fn is_ssz_fixed_len() -> bool {
false
Expand Down
11 changes: 6 additions & 5 deletions src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where
}
}

impl<T: Default + Value, N: Unsigned> Default for Vector<T, N> {
impl<T: Default + Value, N: Unsigned, U: UpdateMap<T>> Default for Vector<T, N, U> {
fn default() -> Self {
Self::from_elem(T::default()).unwrap_or_else(|e| {
panic!(
Expand All @@ -250,7 +250,7 @@ impl<T: Default + Value, N: Unsigned> Default for Vector<T, N> {
}
}

impl<T: Value + Send + Sync, N: Unsigned> tree_hash::TreeHash for Vector<T, N> {
impl<T: Value + Send + Sync, N: Unsigned, U: UpdateMap<T>> tree_hash::TreeHash for Vector<T, N, U> {
fn tree_hash_type() -> tree_hash::TreeHashType {
tree_hash::TreeHashType::Vector
}
Expand All @@ -270,10 +270,11 @@ impl<T: Value + Send + Sync, N: Unsigned> tree_hash::TreeHash for Vector<T, N> {
}
}

impl<T, N> TryFromIter<T> for Vector<T, N>
impl<T, N, U> TryFromIter<T> for Vector<T, N, U>
where
T: Value,
N: Unsigned,
U: UpdateMap<T>,
{
type Error = Error;

Expand All @@ -295,7 +296,7 @@ impl<'a, T: Value, N: Unsigned, U: UpdateMap<T>> IntoIterator for &'a Vector<T,
}

// FIXME: duplicated from `ssz::encode::impl_for_vec`
impl<T: Value, N: Unsigned> Encode for Vector<T, N> {
impl<T: Value, N: Unsigned, U: UpdateMap<T>> Encode for Vector<T, N, U> {
fn is_ssz_fixed_len() -> bool {
<T as Encode>::is_ssz_fixed_len()
}
Expand Down Expand Up @@ -337,7 +338,7 @@ impl<T: Value, N: Unsigned> Encode for Vector<T, N> {
}
}

impl<T: Value, N: Unsigned> Decode for Vector<T, N> {
impl<T: Value, N: Unsigned, U: UpdateMap<T>> Decode for Vector<T, N, U> {
fn is_ssz_fixed_len() -> bool {
<T as Decode>::is_ssz_fixed_len()
}
Expand Down

0 comments on commit 7b42785

Please sign in to comment.