Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions version-ranges/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,39 @@ 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()
}

fn size_hint(&self) -> (usize, Option<usize>) {
(self.0.len(), Some(self.0.len()))
}
}

impl<V> ExactSizeIterator for RangesIter<V> {}

impl<V> DoubleEndedIterator for RangesIter<V> {
fn next_back(&mut self) -> Option<Self::Item> {
self.0.next_back()
}
}

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