@@ -40,6 +40,8 @@ use std::ops::Deref;
4040
4141pub use prometheus_client_derive_text_encode:: * ;
4242
43+ /// Encode the metrics registered with the provided [`Registry`] into the
44+ /// provided [`Write`]r using the OpenMetrics text format.
4345pub fn encode < W , M > ( writer : & mut W , registry : & Registry < M > ) -> Result < ( ) , std:: io:: Error >
4446where
4547 W : Write ,
9294 Ok ( ( ) )
9395}
9496
97+ /// OpenMetrics text encoding for a value.
9598pub trait Encode {
99+ /// Encode to OpenMetrics text encoding.
96100 fn encode ( & self , writer : & mut dyn Write ) -> Result < ( ) , std:: io:: Error > ;
97101}
98102
@@ -304,6 +308,7 @@ impl<'a, 'b> Encoder<'a, 'b> {
304308 }
305309}
306310
311+ /// Used to encode an OpenMetrics Histogram bucket.
307312#[ allow( missing_debug_implementations) ]
308313#[ must_use]
309314pub struct BucketEncoder < ' a > {
@@ -344,6 +349,7 @@ impl<'a> BucketEncoder<'a> {
344349 }
345350}
346351
352+ /// Used to encode an OpenMetrics metric value.
347353#[ allow( missing_debug_implementations) ]
348354#[ must_use]
349355pub struct ValueEncoder < ' a > {
@@ -362,6 +368,7 @@ impl<'a> ValueEncoder<'a> {
362368 }
363369}
364370
371+ /// Used to encode an OpenMetrics Exemplar.
365372#[ allow( missing_debug_implementations) ]
366373#[ must_use]
367374pub struct ExemplarEncoder < ' a > {
@@ -389,10 +396,12 @@ impl<'a> ExemplarEncoder<'a> {
389396 }
390397}
391398
392- /// Trait implemented by each metric type, e.g. [`Counter`], to implement its encoding.
399+ /// Trait implemented by each metric type, e.g. [`Counter`], to implement its encoding in the OpenMetric text format .
393400pub trait EncodeMetric {
401+ /// Encode the given instance in the OpenMetrics text encoding.
394402 fn encode ( & self , encoder : Encoder ) -> Result < ( ) , std:: io:: Error > ;
395403
404+ /// The OpenMetrics metric type of the instance.
396405 // One can not use [`TypedMetric`] directly, as associated constants are not
397406 // object safe and thus can not be used with dynamic dispatching.
398407 fn metric_type ( & self ) -> MetricType ;
@@ -408,6 +417,7 @@ impl EncodeMetric for Box<dyn EncodeMetric> {
408417 }
409418}
410419
420+ /// Trait combining [`EncodeMetric`], [`Send`] and [`Sync`].
411421pub trait SendSyncEncodeMetric : EncodeMetric + Send + Sync { }
412422
413423impl < T : EncodeMetric + Send + Sync > SendSyncEncodeMetric for T { }
0 commit comments