Skip to content

Commit

Permalink
Add IntoIter on Ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Nov 8, 2024
1 parent 216f3fd commit 9be5835
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions version-ranges/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,27 @@ impl<V: Ord + Clone> Ranges<V> {
}
}

// Newtype to avoid leaking our internal representation.
pub struct RangesIter<V>(smallvec::IntoIter<[Interval<V>; 1]>);

impl<V> Iterator for RangesIter<V> {
type Item = Interval<V>;

fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}

impl<V> IntoIterator for Ranges<V> {
type Item = (Bound<V>, Bound<V>);
// Newtype to avoid leaking our internal representation.
type IntoIter = RangesIter<V>;

fn into_iter(self) -> Self::IntoIter {
RangesIter(self.segments.into_iter())
}
}

// REPORT ######################################################################

impl<V: Display + Eq> Display for Ranges<V> {
Expand Down

0 comments on commit 9be5835

Please sign in to comment.