@@ -226,11 +226,6 @@ impl MetricsSet {
226226 self . metrics . push ( metric)
227227 }
228228
229- /// Extends the current list of metrics with the provided ones
230- pub fn extend ( & mut self , metrics : impl IntoIterator < Item = Arc < Metric > > ) {
231- self . metrics . extend ( metrics)
232- }
233-
234229 /// Returns an iterator across all metrics
235230 pub fn iter ( & self ) -> impl Iterator < Item = & Arc < Metric > > {
236231 self . metrics . iter ( )
@@ -447,6 +442,21 @@ impl IntoIterator for MetricsSet {
447442 }
448443}
449444
445+ impl < ' a > IntoIterator for & ' a MetricsSet {
446+ type Item = & ' a Arc < Metric > ;
447+ type IntoIter = std:: slice:: Iter < ' a , Arc < Metric > > ;
448+
449+ fn into_iter ( self ) -> Self :: IntoIter {
450+ self . metrics . iter ( )
451+ }
452+ }
453+
454+ impl Extend < Arc < Metric > > for MetricsSet {
455+ fn extend < I : IntoIterator < Item = Arc < Metric > > > ( & mut self , iter : I ) {
456+ self . metrics . extend ( iter) ;
457+ }
458+ }
459+
450460impl FromIterator < Arc < Metric > > for MetricsSet {
451461 fn from_iter < T : IntoIterator < Item = Arc < Metric > > > ( iter : T ) -> Self {
452462 Self {
@@ -783,6 +793,52 @@ mod tests {
783793 } ;
784794 }
785795
796+ #[ test]
797+ fn test_extend ( ) {
798+ let mut metrics = MetricsSet :: new ( ) ;
799+ let m1 = Arc :: new ( Metric :: new ( MetricValue :: OutputRows ( Count :: new ( ) ) , None ) ) ;
800+ let m2 = Arc :: new ( Metric :: new ( MetricValue :: SpillCount ( Count :: new ( ) ) , None ) ) ;
801+
802+ metrics. extend ( [ Arc :: clone ( & m1) , Arc :: clone ( & m2) ] ) ;
803+ assert_eq ! ( metrics. iter( ) . count( ) , 2 ) ;
804+
805+ let m3 = Arc :: new ( Metric :: new ( MetricValue :: SpilledBytes ( Count :: new ( ) ) , None ) ) ;
806+ metrics. extend ( std:: iter:: once ( Arc :: clone ( & m3) ) ) ;
807+ assert_eq ! ( metrics. iter( ) . count( ) , 3 ) ;
808+ }
809+
810+ #[ test]
811+ fn test_collect ( ) {
812+ let m1 = Arc :: new ( Metric :: new ( MetricValue :: OutputRows ( Count :: new ( ) ) , None ) ) ;
813+ let m2 = Arc :: new ( Metric :: new ( MetricValue :: SpillCount ( Count :: new ( ) ) , None ) ) ;
814+
815+ let metrics: MetricsSet =
816+ vec ! [ Arc :: clone( & m1) , Arc :: clone( & m2) ] . into_iter ( ) . collect ( ) ;
817+ assert_eq ! ( metrics. iter( ) . count( ) , 2 ) ;
818+
819+ let empty: MetricsSet = std:: iter:: empty ( ) . collect ( ) ;
820+ assert_eq ! ( empty. iter( ) . count( ) , 0 ) ;
821+ }
822+
823+ #[ test]
824+ fn test_into_iterator_by_ref ( ) {
825+ let mut metrics = MetricsSet :: new ( ) ;
826+ metrics. push ( Arc :: new ( Metric :: new (
827+ MetricValue :: OutputRows ( Count :: new ( ) ) ,
828+ None ,
829+ ) ) ) ;
830+ metrics. push ( Arc :: new ( Metric :: new (
831+ MetricValue :: SpillCount ( Count :: new ( ) ) ,
832+ None ,
833+ ) ) ) ;
834+
835+ let mut count = 0 ;
836+ for _m in & metrics {
837+ count += 1 ;
838+ }
839+ assert_eq ! ( count, 2 ) ;
840+ }
841+
786842 #[ test]
787843 fn test_sorted_for_display ( ) {
788844 let metrics = ExecutionPlanMetricsSet :: new ( ) ;
0 commit comments