@@ -77,15 +77,15 @@ macro_rules! for_both {
77
77
}
78
78
79
79
impl < ' a > MetricEncoder < ' a > {
80
- pub fn encode_counter < S : EncodeLabelSet , V : EncodeExemplarValue > (
80
+ pub fn encode_counter < S : EncodeLabelSet > (
81
81
& mut self ,
82
- v : impl EncodeCounterValue ,
83
- exemplar : Option < & Exemplar < S , V > > ,
82
+ v : Number ,
83
+ exemplar : Option < & Exemplar < S > > ,
84
84
) -> Result < ( ) , std:: fmt:: Error > {
85
85
for_both ! ( self , e, e. encode_counter( v, exemplar) )
86
86
}
87
87
88
- pub fn encode_gauge ( & mut self , v : impl EncodeGaugeValue ) -> Result < ( ) , std:: fmt:: Error > {
88
+ pub fn encode_gauge ( & mut self , v : Number ) -> Result < ( ) , std:: fmt:: Error > {
89
89
for_both ! ( self , e, e. encode_gauge( v) )
90
90
}
91
91
@@ -98,7 +98,7 @@ impl<'a> MetricEncoder<'a> {
98
98
sum : f64 ,
99
99
count : u64 ,
100
100
buckets : & [ ( f64 , u64 ) ] ,
101
- exemplars : Option < & HashMap < usize , Exemplar < S , f64 > > > ,
101
+ exemplars : Option < & HashMap < usize , Exemplar < S > > > ,
102
102
) -> Result < ( ) , std:: fmt:: Error > {
103
103
for_both ! ( self , e, e. encode_histogram( sum, count, buckets, exemplars) )
104
104
}
@@ -320,145 +320,19 @@ impl<'a> EncodeLabelValue for u64 {
320
320
}
321
321
}
322
322
323
- pub trait EncodeGaugeValue {
324
- /// Encode the given instance in the OpenMetrics text encoding.
325
- fn encode ( & self , encoder : & mut GaugeValueEncoder ) -> Result < ( ) , std:: fmt:: Error > ;
326
- }
327
-
328
- impl EncodeGaugeValue for i64 {
329
- fn encode ( & self , encoder : & mut GaugeValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
330
- encoder. encode_i64 ( * self )
331
- }
332
- }
333
-
334
- impl EncodeGaugeValue for f64 {
335
- fn encode ( & self , encoder : & mut GaugeValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
336
- encoder. encode_f64 ( * self )
337
- }
338
- }
339
-
340
- pub enum GaugeValueEncoder < ' a > {
341
- Text ( text:: GaugeValueEncoder < ' a > ) ,
342
- Protobuf ( proto:: GaugeValueEncoder ) ,
323
+ #[ derive( Debug , Clone , Copy ) ]
324
+ pub enum Number {
325
+ SignedInteger ( i64 ) ,
326
+ UnsignedInteger ( u64 ) ,
327
+ Double ( f64 ) ,
343
328
}
344
329
345
- impl < ' a > GaugeValueEncoder < ' a > {
346
- fn encode_f64 ( & mut self , v : f64 ) -> Result < ( ) , std :: fmt :: Error > {
330
+ impl Number {
331
+ pub fn as_f64 ( self ) -> f64 {
347
332
match self {
348
- GaugeValueEncoder :: Text ( e) => e. encode_f64 ( v) ,
349
- GaugeValueEncoder :: Protobuf ( e) => e. encode_f64 ( v) ,
333
+ Number :: SignedInteger ( i) => i as f64 ,
334
+ Number :: UnsignedInteger ( i) => i as f64 ,
335
+ Number :: Double ( d) => d,
350
336
}
351
337
}
352
-
353
- fn encode_i64 ( & mut self , v : i64 ) -> Result < ( ) , std:: fmt:: Error > {
354
- match self {
355
- GaugeValueEncoder :: Text ( e) => e. encode_i64 ( v) ,
356
- GaugeValueEncoder :: Protobuf ( e) => e. encode_i64 ( v) ,
357
- }
358
- }
359
- }
360
-
361
- impl < ' a > From < text:: GaugeValueEncoder < ' a > > for GaugeValueEncoder < ' a > {
362
- fn from ( e : text:: GaugeValueEncoder < ' a > ) -> Self {
363
- GaugeValueEncoder :: Text ( e)
364
- }
365
- }
366
-
367
- impl < ' a > From < proto:: GaugeValueEncoder > for GaugeValueEncoder < ' a > {
368
- fn from ( e : proto:: GaugeValueEncoder ) -> Self {
369
- GaugeValueEncoder :: Protobuf ( e)
370
- }
371
- }
372
-
373
- pub trait EncodeCounterValue {
374
- /// Encode the given instance in the OpenMetrics text encoding.
375
- fn encode ( & self , encoder : & mut CounterValueEncoder ) -> Result < ( ) , std:: fmt:: Error > ;
376
- }
377
-
378
- impl EncodeCounterValue for u64 {
379
- fn encode ( & self , encoder : & mut CounterValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
380
- encoder. encode_u64 ( * self )
381
- }
382
- }
383
-
384
- impl EncodeCounterValue for f64 {
385
- fn encode ( & self , encoder : & mut CounterValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
386
- encoder. encode_f64 ( * self )
387
- }
388
- }
389
-
390
- pub enum CounterValueEncoder < ' a > {
391
- Text ( text:: CounterValueEncoder < ' a > ) ,
392
- Protobuf ( proto:: CounterValueEncoder ) ,
393
- }
394
-
395
- impl < ' a > CounterValueEncoder < ' a > {
396
- fn encode_f64 ( & mut self , v : f64 ) -> Result < ( ) , std:: fmt:: Error > {
397
- match self {
398
- CounterValueEncoder :: Text ( e) => e. encode_f64 ( v) ,
399
- CounterValueEncoder :: Protobuf ( e) => e. encode_f64 ( v) ,
400
- }
401
- }
402
-
403
- fn encode_u64 ( & mut self , v : u64 ) -> Result < ( ) , std:: fmt:: Error > {
404
- match self {
405
- CounterValueEncoder :: Text ( e) => e. encode_u64 ( v) ,
406
- CounterValueEncoder :: Protobuf ( e) => e. encode_u64 ( v) ,
407
- }
408
- }
409
- }
410
-
411
- pub trait EncodeExemplarValue {
412
- /// Encode the given instance in the OpenMetrics text encoding.
413
- fn encode ( & self , encoder : ExemplarValueEncoder ) -> Result < ( ) , std:: fmt:: Error > ;
414
- }
415
-
416
- impl EncodeExemplarValue for f64 {
417
- fn encode ( & self , mut encoder : ExemplarValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
418
- encoder. encode ( * self )
419
- }
420
- }
421
-
422
- impl EncodeExemplarValue for u64 {
423
- fn encode ( & self , mut encoder : ExemplarValueEncoder ) -> Result < ( ) , std:: fmt:: Error > {
424
- encoder. encode ( * self as f64 )
425
- }
426
- }
427
-
428
- impl < ' a > From < text:: CounterValueEncoder < ' a > > for CounterValueEncoder < ' a > {
429
- fn from ( e : text:: CounterValueEncoder < ' a > ) -> Self {
430
- CounterValueEncoder :: Text ( e)
431
- }
432
- }
433
-
434
- impl < ' a > From < proto:: CounterValueEncoder > for CounterValueEncoder < ' a > {
435
- fn from ( e : proto:: CounterValueEncoder ) -> Self {
436
- CounterValueEncoder :: Protobuf ( e)
437
- }
438
- }
439
-
440
- pub enum ExemplarValueEncoder < ' a > {
441
- Text ( text:: ExemplarValueEncoder < ' a > ) ,
442
- Protobuf ( proto:: ExemplarValueEncoder < ' a > ) ,
443
- }
444
-
445
- impl < ' a > ExemplarValueEncoder < ' a > {
446
- fn encode ( & mut self , v : f64 ) -> Result < ( ) , std:: fmt:: Error > {
447
- match self {
448
- ExemplarValueEncoder :: Text ( e) => e. encode ( v) ,
449
- ExemplarValueEncoder :: Protobuf ( e) => e. encode ( v) ,
450
- }
451
- }
452
- }
453
-
454
- impl < ' a > From < text:: ExemplarValueEncoder < ' a > > for ExemplarValueEncoder < ' a > {
455
- fn from ( e : text:: ExemplarValueEncoder < ' a > ) -> Self {
456
- ExemplarValueEncoder :: Text ( e)
457
- }
458
- }
459
-
460
- impl < ' a > From < proto:: ExemplarValueEncoder < ' a > > for ExemplarValueEncoder < ' a > {
461
- fn from ( e : proto:: ExemplarValueEncoder < ' a > ) -> Self {
462
- ExemplarValueEncoder :: Protobuf ( e)
463
- }
464
338
}
0 commit comments