File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,7 @@ impl<V: Ord> Ranges<V> {
283283 }
284284 }
285285
286+ /// See `Ranges` docstring for the invariants.
286287 fn check_invariants ( self ) -> Self {
287288 if cfg ! ( debug_assertions) {
288289 for p in self . segments . as_slice ( ) . windows ( 2 ) {
@@ -826,6 +827,27 @@ impl<V: Ord + Clone> Ranges<V> {
826827 }
827828}
828829
830+ // Newtype to avoid leaking our internal representation.
831+ pub struct RangesIter < V > ( smallvec:: IntoIter < [ Interval < V > ; 1 ] > ) ;
832+
833+ impl < V > Iterator for RangesIter < V > {
834+ type Item = Interval < V > ;
835+
836+ fn next ( & mut self ) -> Option < Self :: Item > {
837+ self . 0 . next ( )
838+ }
839+ }
840+
841+ impl < V > IntoIterator for Ranges < V > {
842+ type Item = ( Bound < V > , Bound < V > ) ;
843+ // Newtype to avoid leaking our internal representation.
844+ type IntoIter = RangesIter < V > ;
845+
846+ fn into_iter ( self ) -> Self :: IntoIter {
847+ RangesIter ( self . segments . into_iter ( ) )
848+ }
849+ }
850+
829851// REPORT ######################################################################
830852
831853impl < V : Display + Eq > Display for Ranges < V > {
You can’t perform that action at this time.
0 commit comments