Skip to content

Commit 9be5835

Browse files
committed
Add IntoIter on Ranges
1 parent 216f3fd commit 9be5835

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

version-ranges/src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,27 @@ impl<V: Ord + Clone> Ranges<V> {
826826
}
827827
}
828828

829+
// Newtype to avoid leaking our internal representation.
830+
pub struct RangesIter<V>(smallvec::IntoIter<[Interval<V>; 1]>);
831+
832+
impl<V> Iterator for RangesIter<V> {
833+
type Item = Interval<V>;
834+
835+
fn next(&mut self) -> Option<Self::Item> {
836+
self.0.next()
837+
}
838+
}
839+
840+
impl<V> IntoIterator for Ranges<V> {
841+
type Item = (Bound<V>, Bound<V>);
842+
// Newtype to avoid leaking our internal representation.
843+
type IntoIter = RangesIter<V>;
844+
845+
fn into_iter(self) -> Self::IntoIter {
846+
RangesIter(self.segments.into_iter())
847+
}
848+
}
849+
829850
// REPORT ######################################################################
830851

831852
impl<V: Display + Eq> Display for Ranges<V> {

0 commit comments

Comments
 (0)