Skip to content

Commit

Permalink
iter: add current_depth and root_depth
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Nov 19, 2024
1 parent 0911404 commit 9009808
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion miniconf/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ impl<T: Iterator> Iterator for ExactSize<T> {
}
}

impl<T> ExactSize<T> {
/// Return a reference to the inner iterator
#[inline]
pub fn inner(&self) -> &T {
&self.iter
}
}

// Even though general TreeKey iterations may well be longer than usize::MAX
// we are sure that the aren't in this case since self.count <= usize::MAX
impl<T: Iterator> ExactSizeIterator for ExactSize<T> {}
Expand All @@ -52,6 +60,7 @@ impl<T: Keys> Keys for Consume<T> {
Ok(())
}
}

impl<T: Keys> IntoKeys for Consume<T> {
type IntoKeys = Self;

Expand Down Expand Up @@ -127,6 +136,16 @@ impl<M: TreeKey + ?Sized, N, const D: usize> NodeIter<M, N, D> {
count: meta.count,
}
}

/// Return the current iteration depth
pub fn current_depth(&self) -> usize {
self.depth
}

/// Return the root depth
pub fn root_depth(&self) -> usize {
self.root
}
}

impl<M, N, const D: usize> Iterator for NodeIter<M, N, D>
Expand Down Expand Up @@ -173,7 +192,7 @@ where
}
}

// Do not allow manipulation of `depth` other than through iteration.
// Contract: Do not allow manipulation of `depth` other than through iteration.
impl<M: TreeKey + ?Sized, N: Transcode + Default, const D: usize> core::iter::FusedIterator
for NodeIter<M, N, D>
{
Expand Down

0 comments on commit 9009808

Please sign in to comment.