@@ -6,83 +6,84 @@ use crate::{error::OTelSdkResult, Resource};
66use std:: { fmt:: Debug , slice:: Iter , time:: Duration } ;
77
88use super :: {
9- data:: { Metric , ResourceMetrics , ScopeMetrics } ,
9+ data:: Metric ,
10+ reader:: { ResourceMetricsData , ScopeMetricsData } ,
1011 Temporality ,
1112} ;
1213
1314/// A collection of [`BatchScopeMetrics`] and the associated [Resource] that created them.
1415#[ derive( Debug ) ]
15- pub struct ResourceMetricsRef < ' a > {
16+ pub struct ResourceMetrics < ' a > {
1617 /// The entity that collected the metrics.
1718 pub resource : & ' a Resource ,
1819 /// The collection of metrics with unique [InstrumentationScope]s.
19- pub scope_metrics : BatchScopeMetrics < ' a > ,
20+ pub scope_metrics : ScopeMetricsLendingIter < ' a > ,
2021}
2122
2223/// Iterator over libraries instrumentation scopes ([`InstrumentationScope`]) together with metrics.
23- pub struct BatchScopeMetrics < ' a > {
24- iter : Iter < ' a , ScopeMetrics > ,
24+ /// Doesn't implement standard [`Iterator`], because it returns borrowed items. AKA "LendingIterator".
25+ pub struct ScopeMetricsLendingIter < ' a > {
26+ iter : Iter < ' a , ScopeMetricsData > ,
2527}
2628
2729/// A collection of metrics produced by a [`InstrumentationScope`] meter.
2830#[ derive( Debug ) ]
29- pub struct ScopeMetricsRef < ' a > {
31+ pub struct ScopeMetrics < ' a > {
3032 /// The [InstrumentationScope] that the meter was created with.
3133 pub scope : & ' a InstrumentationScope ,
3234 /// The list of aggregations created by the meter.
33- pub metrics : BatchMetrics < ' a > ,
35+ pub metrics : MetricsLendingIter < ' a > ,
3436}
3537
3638/// Iterator over aggregations created by the meter.
37- pub struct BatchMetrics < ' a > {
39+ /// Doesn't implement standard [`Iterator`], because it returns borrowed items. AKA "LendingIterator".
40+ pub struct MetricsLendingIter < ' a > {
3841 iter : Iter < ' a , Metric > ,
3942}
4043
41- impl < ' a > ResourceMetricsRef < ' a > {
42- pub ( crate ) fn new ( rm : & ' a ResourceMetrics ) -> Self {
44+ impl < ' a > ResourceMetrics < ' a > {
45+ pub ( crate ) fn new ( rm : & ' a ResourceMetricsData ) -> Self {
4346 Self {
4447 resource : & rm. resource ,
45- scope_metrics : BatchScopeMetrics {
48+ scope_metrics : ScopeMetricsLendingIter {
4649 iter : rm. scope_metrics . iter ( ) ,
4750 } ,
4851 }
4952 }
5053}
5154
52- impl < ' a > ScopeMetricsRef < ' a > {
53- fn new ( sm : & ' a ScopeMetrics ) -> Self {
55+ impl < ' a > ScopeMetrics < ' a > {
56+ fn new ( sm : & ' a ScopeMetricsData ) -> Self {
5457 Self {
5558 scope : & sm. scope ,
56- metrics : BatchMetrics {
59+ metrics : MetricsLendingIter {
5760 iter : sm. metrics . iter ( ) ,
5861 } ,
5962 }
6063 }
6164}
6265
63- impl Debug for BatchScopeMetrics < ' _ > {
66+ impl Debug for ScopeMetricsLendingIter < ' _ > {
6467 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
6568 f. debug_struct ( "BatchScopeMetrics" ) . finish ( )
6669 }
6770}
6871
69- impl < ' a > Iterator for BatchScopeMetrics < ' a > {
70- type Item = ScopeMetricsRef < ' a > ;
71-
72- fn next ( & mut self ) -> Option < Self :: Item > {
73- self . iter . next ( ) . map ( ScopeMetricsRef :: new)
72+ impl ScopeMetricsLendingIter < ' _ > {
73+ /// Advances the iterator and returns the next value.
74+ pub fn next ( & mut self ) -> Option < ScopeMetrics < ' _ > > {
75+ self . iter . next ( ) . map ( ScopeMetrics :: new)
7476 }
7577}
7678
77- impl < ' a > Iterator for BatchMetrics < ' a > {
78- type Item = & ' a Metric ;
79-
80- fn next ( & mut self ) -> Option < Self :: Item > {
79+ impl MetricsLendingIter < ' _ > {
80+ /// Advances the iterator and returns the next value.
81+ pub fn next ( & mut self ) -> Option < & Metric > {
8182 self . iter . next ( )
8283 }
8384}
8485
85- impl Debug for BatchMetrics < ' _ > {
86+ impl Debug for MetricsLendingIter < ' _ > {
8687 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
8788 f. debug_struct ( "BatchMetrics" ) . finish ( )
8889 }
@@ -99,7 +100,7 @@ pub trait PushMetricExporter: Send + Sync + 'static {
99100 /// considered unrecoverable and will be logged.
100101 fn export (
101102 & self ,
102- metrics : ResourceMetricsRef < ' _ > ,
103+ metrics : ResourceMetrics < ' _ > ,
103104 ) -> impl std:: future:: Future < Output = OTelSdkResult > + Send ;
104105
105106 /// Flushes any metric data held by an exporter.
0 commit comments