From 7d060f01cdf03931e1a75f8f99a5d367331872a4 Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Tue, 28 May 2024 11:01:22 +0200 Subject: [PATCH] add iter on FilterSet (#784) --- crates/rpc-types/src/eth/filter.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types/src/eth/filter.rs b/crates/rpc-types/src/eth/filter.rs index a6621edcc07..57b67b94484 100644 --- a/crates/rpc-types/src/eth/filter.rs +++ b/crates/rpc-types/src/eth/filter.rs @@ -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}, }; @@ -84,6 +87,15 @@ impl From>> for FilterSet { } } +impl IntoIterator for FilterSet { + type Item = T; + type IntoIter = IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + impl FilterSet { /// Returns whether the filter is empty pub fn is_empty(&self) -> bool { @@ -95,6 +107,12 @@ impl FilterSet { 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 + Eq + Hash> FilterSet {