diff --git a/version-ranges/src/lib.rs b/version-ranges/src/lib.rs index 0e33bd5c..accac912 100644 --- a/version-ranges/src/lib.rs +++ b/version-ranges/src/lib.rs @@ -826,6 +826,27 @@ impl Ranges { } } +// Newtype to avoid leaking our internal representation. +pub struct RangesIter(smallvec::IntoIter<[Interval; 1]>); + +impl Iterator for RangesIter { + type Item = Interval; + + fn next(&mut self) -> Option { + self.0.next() + } +} + +impl IntoIterator for Ranges { + type Item = (Bound, Bound); + // Newtype to avoid leaking our internal representation. + type IntoIter = RangesIter; + + fn into_iter(self) -> Self::IntoIter { + RangesIter(self.segments.into_iter()) + } +} + // REPORT ###################################################################### impl Display for Ranges {