Skip to content

Commit 0ef5e54

Browse files
committed
Move TreeLike impl to concrete module
When we implemented the `TreeLike` trait for the concrete `Policy` we put it in the `iter` module, it doesn't really live there, better to put the impl in the same place as the definition of the implementor. Move the impl of `TreeLike` for `concrete::Policy` to the `concrete` module.
1 parent 161753c commit 0ef5e54

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/iter/mod.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use tree::{
1515
};
1616

1717
use crate::sync::Arc;
18-
use crate::{policy, Miniscript, MiniscriptKey, ScriptContext, Terminal};
18+
use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};
1919

2020
impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for &'a Miniscript<Pk, Ctx> {
2121
fn as_node(&self) -> Tree<Self> {
@@ -68,29 +68,3 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>
6868
}
6969
}
7070
}
71-
72-
impl<'a, Pk: MiniscriptKey> TreeLike for &'a policy::Concrete<Pk> {
73-
fn as_node(&self) -> Tree<Self> {
74-
use policy::Concrete::*;
75-
match *self {
76-
Unsatisfiable | Trivial | Key(_) | After(_) | Older(_) | Sha256(_) | Hash256(_)
77-
| Ripemd160(_) | Hash160(_) => Tree::Nullary,
78-
And(ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
79-
Or(ref v) => Tree::Nary(v.iter().map(|(_, p)| p.as_ref()).collect()),
80-
Threshold(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
81-
}
82-
}
83-
}
84-
85-
impl<Pk: MiniscriptKey> TreeLike for Arc<policy::Concrete<Pk>> {
86-
fn as_node(&self) -> Tree<Self> {
87-
use policy::Concrete::*;
88-
match self.as_ref() {
89-
Unsatisfiable | Trivial | Key(_) | After(_) | Older(_) | Sha256(_) | Hash256(_)
90-
| Ripemd160(_) | Hash160(_) => Tree::Nullary,
91-
And(ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
92-
Or(ref v) => Tree::Nary(v.iter().map(|(_, p)| Arc::clone(p)).collect()),
93-
Threshold(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
94-
}
95-
}
96-
}

src/policy/concrete.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {
2323

2424
use super::ENTAILMENT_MAX_TERMINALS;
2525
use crate::expression::{self, FromTree};
26-
use crate::iter::TreeLike;
26+
use crate::iter::{Tree, TreeLike};
2727
use crate::miniscript::types::extra_props::TimelockInfo;
2828
use crate::prelude::*;
2929
use crate::sync::Arc;
@@ -1114,6 +1114,34 @@ fn generate_combination<Pk: MiniscriptKey>(
11141114
ret
11151115
}
11161116

1117+
impl<'a, Pk: MiniscriptKey> TreeLike for &'a Policy<Pk> {
1118+
fn as_node(&self) -> Tree<Self> {
1119+
use Policy::*;
1120+
1121+
match *self {
1122+
Unsatisfiable | Trivial | Key(_) | After(_) | Older(_) | Sha256(_) | Hash256(_)
1123+
| Ripemd160(_) | Hash160(_) => Tree::Nullary,
1124+
And(ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
1125+
Or(ref v) => Tree::Nary(v.iter().map(|(_, p)| p.as_ref()).collect()),
1126+
Threshold(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
1127+
}
1128+
}
1129+
}
1130+
1131+
impl<Pk: MiniscriptKey> TreeLike for Arc<Policy<Pk>> {
1132+
fn as_node(&self) -> Tree<Self> {
1133+
use Policy::*;
1134+
1135+
match self.as_ref() {
1136+
Unsatisfiable | Trivial | Key(_) | After(_) | Older(_) | Sha256(_) | Hash256(_)
1137+
| Ripemd160(_) | Hash160(_) => Tree::Nullary,
1138+
And(ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
1139+
Or(ref v) => Tree::Nary(v.iter().map(|(_, p)| Arc::clone(p)).collect()),
1140+
Threshold(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
1141+
}
1142+
}
1143+
}
1144+
11171145
#[cfg(all(test, feature = "compiler"))]
11181146
mod compiler_tests {
11191147
use core::str::FromStr;

0 commit comments

Comments
 (0)