Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract over U: UpdateMap more #61

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading