File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -846,6 +846,39 @@ impl<V: Ord + Clone> Ranges<V> {
846846 }
847847}
848848
849+ // Newtype to avoid leaking our internal representation.
850+ pub struct RangesIter < V > ( smallvec:: IntoIter < [ Interval < V > ; 1 ] > ) ;
851+
852+ impl < V > Iterator for RangesIter < V > {
853+ type Item = Interval < V > ;
854+
855+ fn next ( & mut self ) -> Option < Self :: Item > {
856+ self . 0 . next ( )
857+ }
858+
859+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
860+ ( self . 0 . len ( ) , Some ( self . 0 . len ( ) ) )
861+ }
862+ }
863+
864+ impl < V > ExactSizeIterator for RangesIter < V > { }
865+
866+ impl < V > DoubleEndedIterator for RangesIter < V > {
867+ fn next_back ( & mut self ) -> Option < Self :: Item > {
868+ self . 0 . next_back ( )
869+ }
870+ }
871+
872+ impl < V > IntoIterator for Ranges < V > {
873+ type Item = ( Bound < V > , Bound < V > ) ;
874+ // Newtype to avoid leaking our internal representation.
875+ type IntoIter = RangesIter < V > ;
876+
877+ fn into_iter ( self ) -> Self :: IntoIter {
878+ RangesIter ( self . segments . into_iter ( ) )
879+ }
880+ }
881+
849882// REPORT ######################################################################
850883
851884impl < V : Display + Eq > Display for Ranges < V > {
You can’t perform that action at this time.
0 commit comments