Skip to content

Commit 38d11ae

Browse files
committed
Add IntoIter on Ranges
1 parent 36c2e41 commit 38d11ae

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
@@ -846,6 +846,27 @@ impl<V: Ord + Clone> Ranges<V> {
846846
}
847847
}
848848

849+
// Newtype to avoid leaking our internal representation.
850+
pub struct RangesIter<V>(smallvec::IntoIter<[Interval<V>; 1]>);
851+
852+
impl<V> Iterator for RangesIter<V> {
853+
type Item = Interval<V>;
854+
855+
fn next(&mut self) -> Option<Self::Item> {
856+
self.0.next()
857+
}
858+
}
859+
860+
impl<V> IntoIterator for Ranges<V> {
861+
type Item = (Bound<V>, Bound<V>);
862+
// Newtype to avoid leaking our internal representation.
863+
type IntoIter = RangesIter<V>;
864+
865+
fn into_iter(self) -> Self::IntoIter {
866+
RangesIter(self.segments.into_iter())
867+
}
868+
}
869+
849870
// REPORT ######################################################################
850871

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

0 commit comments

Comments
 (0)