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> {
283
283
}
284
284
}
285
285
286
+ /// See `Ranges` docstring for the invariants.
286
287
fn check_invariants ( self ) -> Self {
287
288
if cfg ! ( debug_assertions) {
288
289
for p in self . segments . as_slice ( ) . windows ( 2 ) {
@@ -826,6 +827,27 @@ impl<V: Ord + Clone> Ranges<V> {
826
827
}
827
828
}
828
829
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
+
829
851
// REPORT ######################################################################
830
852
831
853
impl < V : Display + Eq > Display for Ranges < V > {
You can’t perform that action at this time.
0 commit comments