Skip to content

Commit 9570d49

Browse files
committed
Add the equivalent of ForEach::as_key() for PkPkh
1 parent de74dc0 commit 9570d49

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/miniscript/iter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ pub enum PkPkh<Pk: MiniscriptKey> {
368368
HashedPubkey(Pk::Hash),
369369
}
370370

371+
impl<Pk: MiniscriptKey<Hash = Pk>> PkPkh<Pk> {
372+
/// Convenience method to avoid distinguishing between keys and hashes when these are the same type
373+
pub fn as_key(self) -> Pk {
374+
match self {
375+
PkPkh::PlainPubkey(pk) => pk,
376+
PkPkh::HashedPubkey(pkh) => pkh,
377+
}
378+
}
379+
}
380+
371381
/// Iterator for traversing all [MiniscriptKey]'s and hashes, depending what data are present in AST,
372382
/// starting from some specific node which constructs the iterator via
373383
/// [Miniscript::iter_pk_pkh] method.

0 commit comments

Comments
 (0)