Skip to content

Commit

Permalink
Add IntoIterator<Item = &Pk> for ConcretePolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Jul 14, 2021
1 parent 85d0f6c commit f521266
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/policy/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk> {
}
}

impl<'a, Pk: MiniscriptKey> IntoIterator for &'a Policy<Pk> {
type Item = &'a Pk;
type IntoIter = Box<dyn Iterator<Item = &'a Pk> + 'a>;

fn into_iter(self) -> Self::IntoIter {
use std::iter;

match *self {
Policy::Key(ref pk) => Box::new(iter::once(pk)),
Policy::Threshold(_, ref subs) | Policy::And(ref subs) => {
Box::new(subs.iter().map(|s| s.into_iter()).flatten())
}
Policy::Or(ref subs) => Box::new(subs.iter().map(|(_, s)| s.into_iter()).flatten()),
Policy::Unsatisfiable
| Policy::Trivial
| Policy::Sha256(..)
| Policy::Hash256(..)
| Policy::Ripemd160(..)
| Policy::Hash160(..)
| Policy::After(..)
| Policy::Older(..) => Box::new(iter::empty()),
}
}
}

impl<Pk: MiniscriptKey> Policy<Pk> {
/// Convert a policy using one kind of public key to another
/// type of public key
Expand Down

0 comments on commit f521266

Please sign in to comment.