Skip to content

Commit

Permalink
Removed IntoIterator for TapTree implementation
Browse files Browse the repository at this point in the history
In the future, TapTree may iterate over different node types, and that's why it does not have `iter()` function; using instead `script_leafs`. Thus, we should not have IntoIterator implementation as well
  • Loading branch information
dr-orlovsky committed Apr 19, 2022
1 parent 7a5482d commit 3c59897
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/util/psbt/map/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@ impl TapTree {
/// Returns [`TapTreeIter`] iterator for a taproot script tree, operating in DFS order over
/// tree [`ScriptLeaf`]s.
pub fn script_leaves(&self) -> TapTreeIter {
self.into_iter()
match (self.0.branch().len(), self.0.branch().last()) {
(1, Some(Some(root))) => {
TapTreeIter {
leaf_iter: root.leaves.iter()
}
}
// This should be unreachable as we Taptree is already finalized
_ => unreachable!("non-finalized tree builder inside TapTree"),
}
}
}

Expand All @@ -177,23 +185,6 @@ impl<'tree> Iterator for TapTreeIter<'tree> {
}
}

impl<'tree> IntoIterator for &'tree TapTree {
type Item = &'tree ScriptLeaf;
type IntoIter = TapTreeIter<'tree>;

fn into_iter(self) -> Self::IntoIter {
match (self.0.branch().len(), self.0.branch().last()) {
(1, Some(Some(root))) => {
TapTreeIter {
leaf_iter: root.leaves.iter()
}
}
// This should be unreachable as we Taptree is already finalized
_ => unreachable!("non-finalized tree builder inside TapTree"),
}
}
}

impl Output {
pub(super) fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error> {
let raw::Pair {
Expand Down

0 comments on commit 3c59897

Please sign in to comment.