Skip to content

Commit c6fa7ca

Browse files
committed
Import Terminal::* to make code more terse
The use of `Terminal::Foo` repeatedly clutters the code with no added meaning, we can import all the variants and make the code more terse and easier to read. Refactor only, no logic changes.
1 parent c3c508e commit c6fa7ca

File tree

1 file changed

+36
-58
lines changed

1 file changed

+36
-58
lines changed

src/iter/mod.rs

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,52 @@ use crate::{Miniscript, MiniscriptKey, ScriptContext, Terminal};
2020

2121
impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for &'a Miniscript<Pk, Ctx> {
2222
fn as_node(&self) -> Tree<Self> {
23+
use Terminal::*;
2324
match self.node {
24-
Terminal::PkK(..)
25-
| Terminal::PkH(..)
26-
| Terminal::RawPkH(..)
27-
| Terminal::After(..)
28-
| Terminal::Older(..)
29-
| Terminal::Sha256(..)
30-
| Terminal::Hash256(..)
31-
| Terminal::Ripemd160(..)
32-
| Terminal::Hash160(..)
33-
| Terminal::True
34-
| Terminal::False
35-
| Terminal::Multi(..)
36-
| Terminal::MultiA(..) => Tree::Nullary,
37-
Terminal::Alt(ref sub)
38-
| Terminal::Swap(ref sub)
39-
| Terminal::Check(ref sub)
40-
| Terminal::DupIf(ref sub)
41-
| Terminal::Verify(ref sub)
42-
| Terminal::NonZero(ref sub)
43-
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(sub),
44-
Terminal::AndV(ref left, ref right)
45-
| Terminal::AndB(ref left, ref right)
46-
| Terminal::OrB(ref left, ref right)
47-
| Terminal::OrD(ref left, ref right)
48-
| Terminal::OrC(ref left, ref right)
49-
| Terminal::OrI(ref left, ref right) => Tree::Binary(left, right),
50-
Terminal::AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
51-
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
25+
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
26+
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
27+
Alt(ref sub)
28+
| Swap(ref sub)
29+
| Check(ref sub)
30+
| DupIf(ref sub)
31+
| Verify(ref sub)
32+
| NonZero(ref sub)
33+
| ZeroNotEqual(ref sub) => Tree::Unary(sub),
34+
AndV(ref left, ref right)
35+
| AndB(ref left, ref right)
36+
| OrB(ref left, ref right)
37+
| OrD(ref left, ref right)
38+
| OrC(ref left, ref right)
39+
| OrI(ref left, ref right) => Tree::Binary(left, right),
40+
AndOr(ref a, ref b, ref c) => Tree::Nary(Arc::from([a.as_ref(), b, c])),
41+
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::as_ref).collect()),
5242
}
5343
}
5444
}
5545

5646
impl<Pk: MiniscriptKey, Ctx: ScriptContext> TreeLike for Arc<Miniscript<Pk, Ctx>> {
5747
fn as_node(&self) -> Tree<Self> {
48+
use Terminal::*;
5849
match self.node {
59-
Terminal::PkK(..)
60-
| Terminal::PkH(..)
61-
| Terminal::RawPkH(..)
62-
| Terminal::After(..)
63-
| Terminal::Older(..)
64-
| Terminal::Sha256(..)
65-
| Terminal::Hash256(..)
66-
| Terminal::Ripemd160(..)
67-
| Terminal::Hash160(..)
68-
| Terminal::True
69-
| Terminal::False
70-
| Terminal::Multi(..)
71-
| Terminal::MultiA(..) => Tree::Nullary,
72-
Terminal::Alt(ref sub)
73-
| Terminal::Swap(ref sub)
74-
| Terminal::Check(ref sub)
75-
| Terminal::DupIf(ref sub)
76-
| Terminal::Verify(ref sub)
77-
| Terminal::NonZero(ref sub)
78-
| Terminal::ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
79-
Terminal::AndV(ref left, ref right)
80-
| Terminal::AndB(ref left, ref right)
81-
| Terminal::OrB(ref left, ref right)
82-
| Terminal::OrD(ref left, ref right)
83-
| Terminal::OrC(ref left, ref right)
84-
| Terminal::OrI(ref left, ref right) => {
85-
Tree::Binary(Arc::clone(left), Arc::clone(right))
86-
}
87-
Terminal::AndOr(ref a, ref b, ref c) => {
50+
PkK(..) | PkH(..) | RawPkH(..) | After(..) | Older(..) | Sha256(..) | Hash256(..)
51+
| Ripemd160(..) | Hash160(..) | True | False | Multi(..) | MultiA(..) => Tree::Nullary,
52+
Alt(ref sub)
53+
| Swap(ref sub)
54+
| Check(ref sub)
55+
| DupIf(ref sub)
56+
| Verify(ref sub)
57+
| NonZero(ref sub)
58+
| ZeroNotEqual(ref sub) => Tree::Unary(Arc::clone(sub)),
59+
AndV(ref left, ref right)
60+
| AndB(ref left, ref right)
61+
| OrB(ref left, ref right)
62+
| OrD(ref left, ref right)
63+
| OrC(ref left, ref right)
64+
| OrI(ref left, ref right) => Tree::Binary(Arc::clone(left), Arc::clone(right)),
65+
AndOr(ref a, ref b, ref c) => {
8866
Tree::Nary(Arc::from([Arc::clone(a), Arc::clone(b), Arc::clone(c)]))
8967
}
90-
Terminal::Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
68+
Thresh(_, ref subs) => Tree::Nary(subs.iter().map(Arc::clone).collect()),
9169
}
9270
}
9371
}

0 commit comments

Comments
 (0)