Skip to content

Commit adf3164

Browse files
committed
tr: improve TapTreeIter a bunch
TapTreeIter is now a wrapper around core::slice::Iter. So we can propagate several traits: ExactSizeIterator, DoubleEndedIterator and FusedIterator. Annoyingly we cannot propagate TrustedLenIterator since that's nightly-only, nor can we propagate Default which was introduced some time after 1.63.0. core::slice::Iter also implements AsRef<&[T]> which is tempting, but we don't propagate that since it feels like it reveals too much about the internals of TapTreeIter.
1 parent 960a6cc commit adf3164

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/descriptor/tr/taptree.rs

+14
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ impl<'tr, Pk: MiniscriptKey> Iterator for TapTreeIter<'tr, Pk> {
161161
}
162162
}
163163

164+
impl<'tr, Pk: MiniscriptKey> DoubleEndedIterator for TapTreeIter<'tr, Pk> {
165+
fn next_back(&mut self) -> Option<Self::Item> {
166+
self.inner
167+
.next_back()
168+
.map(|&(depth, ref node)| TapTreeIterItem { depth, node })
169+
}
170+
}
171+
172+
impl<'tr, Pk: MiniscriptKey> ExactSizeIterator for TapTreeIter<'tr, Pk> {
173+
fn len(&self) -> usize { self.inner.len() }
174+
}
175+
176+
impl<'tr, Pk: MiniscriptKey> core::iter::FusedIterator for TapTreeIter<'tr, Pk> {}
177+
164178
/// Iterator over all of the leaves of a Taproot tree.
165179
///
166180
/// If there is no tree (i.e. this is a keyspend-only Taproot descriptor)

0 commit comments

Comments
 (0)