Skip to content

Commit

Permalink
add iter on FilterSet (#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 authored May 28, 2024
1 parent aed6de2 commit 7d060f0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/rpc-types/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use serde::{
Deserialize, Deserializer, Serialize, Serializer,
};
use std::{
collections::HashSet,
collections::{
hash_set::{IntoIter, Iter},
HashSet,
},
hash::Hash,
ops::{Range, RangeFrom, RangeTo},
};
Expand Down Expand Up @@ -84,6 +87,15 @@ impl<T: Eq + Hash> From<ValueOrArray<Option<T>>> for FilterSet<T> {
}
}

impl<T: Eq + Hash> IntoIterator for FilterSet<T> {
type Item = T;
type IntoIter = IntoIter<T>;

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

impl<T: Eq + Hash> FilterSet<T> {
/// Returns whether the filter is empty
pub fn is_empty(&self) -> bool {
Expand All @@ -95,6 +107,12 @@ impl<T: Eq + Hash> FilterSet<T> {
pub fn matches(&self, value: &T) -> bool {
self.is_empty() || self.0.contains(value)
}

/// Returns an iterator over the underlying HashSet. Values are visited
/// in an arbitrary order.
pub fn iter(&self) -> Iter<'_, T> {
self.0.iter()
}
}

impl<T: AsRef<[u8]> + Eq + Hash> FilterSet<T> {
Expand Down

0 comments on commit 7d060f0

Please sign in to comment.