Skip to content

Commit 9db17e1

Browse files
committed
iface: implement filters for map types
1 parent c810799 commit 9db17e1

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/interface/filters.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// See the License for the specific language governing permissions and
2020
// limitations under the License.
2121

22-
use std::collections::{BTreeSet, HashSet};
22+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
2323
use std::ops::Deref;
2424

2525
use rgb::{AssignmentWitness, XOutpoint};
@@ -99,6 +99,20 @@ impl OutpointFilter for BTreeSet<XOutpoint> {
9999
}
100100
}
101101

102+
impl<V> OutpointFilter for HashMap<XOutpoint, V> {
103+
fn include_outpoint(&self, outpoint: impl Into<XOutpoint>) -> bool {
104+
let outpoint = outpoint.into();
105+
self.keys().any(|o| *o == outpoint)
106+
}
107+
}
108+
109+
impl<V> OutpointFilter for BTreeMap<XOutpoint, V> {
110+
fn include_outpoint(&self, outpoint: impl Into<XOutpoint>) -> bool {
111+
let outpoint = outpoint.into();
112+
self.keys().any(|o| *o == outpoint)
113+
}
114+
}
115+
102116
// WitnessFilter
103117

104118
impl WitnessFilter for FilterIncludeAll {
@@ -166,3 +180,17 @@ impl WitnessFilter for BTreeSet<AssignmentWitness> {
166180
self.contains(&witness.into())
167181
}
168182
}
183+
184+
impl<V> WitnessFilter for HashMap<AssignmentWitness, V> {
185+
fn include_witness(&self, witness: impl Into<AssignmentWitness>) -> bool {
186+
let witness = witness.into();
187+
self.keys().any(|w| *w == witness)
188+
}
189+
}
190+
191+
impl<V> WitnessFilter for BTreeMap<AssignmentWitness, V> {
192+
fn include_witness(&self, witness: impl Into<AssignmentWitness>) -> bool {
193+
let witness = witness.into();
194+
self.keys().any(|w| *w == witness)
195+
}
196+
}

0 commit comments

Comments
 (0)