@@ -217,6 +217,8 @@ impl Encode for () {
217217 }
218218}
219219
220+ /// Helper type for [`EncodeMetric`], see [`EncodeMetric::encode`].
221+ ///
220222// `Encoder` does not take a trait parameter for `writer` and `labels` because
221223// `EncodeMetric` which uses `Encoder` needs to be usable as a trait object in
222224// order to be able to register different metric types with a `Registry`. Trait
@@ -232,6 +234,7 @@ pub struct Encoder<'a, 'b> {
232234}
233235
234236impl < ' a , ' b > Encoder < ' a , ' b > {
237+ /// Encode a metric suffix, e.g. in the case of [`Counter`] the suffic `_total`.
235238 pub fn encode_suffix ( & mut self , suffix : & ' static str ) -> Result < BucketEncoder , std:: io:: Error > {
236239 self . write_name_and_unit ( ) ?;
237240
@@ -241,6 +244,7 @@ impl<'a, 'b> Encoder<'a, 'b> {
241244 self . encode_labels ( )
242245 }
243246
247+ /// Signal that the metric has no suffix.
244248 pub fn no_suffix ( & mut self ) -> Result < BucketEncoder , std:: io:: Error > {
245249 self . write_name_and_unit ( ) ?;
246250
@@ -285,6 +289,7 @@ impl<'a, 'b> Encoder<'a, 'b> {
285289 } )
286290 }
287291
292+ /// Encode a set of labels. Used by wrapper metric types like [`Family`].
288293 pub fn with_label_set < ' c , ' d > ( & ' c mut self , label_set : & ' d dyn Encode ) -> Encoder < ' c , ' d > {
289294 debug_assert ! ( self . labels. is_none( ) ) ;
290295
@@ -305,7 +310,8 @@ pub struct BucketEncoder<'a> {
305310}
306311
307312impl < ' a > BucketEncoder < ' a > {
308- fn encode_bucket ( & mut self , upper_bound : f64 ) -> Result < ValueEncoder , std:: io:: Error > {
313+ /// Encode a bucket. Used for the [`Histogram`] metric type.
314+ pub fn encode_bucket ( & mut self , upper_bound : f64 ) -> Result < ValueEncoder , std:: io:: Error > {
309315 if self . opened_curly_brackets {
310316 self . writer . write_all ( b"," ) ?;
311317 } else {
@@ -325,7 +331,8 @@ impl<'a> BucketEncoder<'a> {
325331 } )
326332 }
327333
328- fn no_bucket ( & mut self ) -> Result < ValueEncoder , std:: io:: Error > {
334+ /// Signal that the metric type has no bucket.
335+ pub fn no_bucket ( & mut self ) -> Result < ValueEncoder , std:: io:: Error > {
329336 if self . opened_curly_brackets {
330337 self . writer . write_all ( b"}" ) ?;
331338 }
@@ -341,7 +348,9 @@ pub struct ValueEncoder<'a> {
341348}
342349
343350impl < ' a > ValueEncoder < ' a > {
344- fn encode_value < V : Encode > ( & mut self , v : V ) -> Result < ExemplarEncoder , std:: io:: Error > {
351+ /// Encode the metric value. E.g. in the case of [`Counter`] the
352+ /// monotonically increasing counter value.
353+ pub fn encode_value < V : Encode > ( & mut self , v : V ) -> Result < ExemplarEncoder , std:: io:: Error > {
345354 self . writer . write_all ( b" " ) ?;
346355 v. encode ( self . writer ) ?;
347356 Ok ( ExemplarEncoder {
@@ -356,7 +365,8 @@ pub struct ExemplarEncoder<'a> {
356365}
357366
358367impl < ' a > ExemplarEncoder < ' a > {
359- fn encode_exemplar < S : Encode , V : Encode > (
368+ /// Encode an exemplar for the given metric.
369+ pub fn encode_exemplar < S : Encode , V : Encode > (
360370 & mut self ,
361371 exemplar : & Exemplar < S , V > ,
362372 ) -> Result < ( ) , std:: io:: Error > {
@@ -368,12 +378,14 @@ impl<'a> ExemplarEncoder<'a> {
368378 Ok ( ( ) )
369379 }
370380
371- fn no_exemplar ( & mut self ) -> Result < ( ) , std:: io:: Error > {
381+ /// Signal that the metric type has no exemplar.
382+ pub fn no_exemplar ( & mut self ) -> Result < ( ) , std:: io:: Error > {
372383 self . writer . write_all ( b"\n " ) ?;
373384 Ok ( ( ) )
374385 }
375386}
376387
388+ /// Trait implemented by each metric type, e.g. [`Counter`], to implement its encoding.
377389pub trait EncodeMetric {
378390 fn encode ( & self , encoder : Encoder ) -> Result < ( ) , std:: io:: Error > ;
379391
0 commit comments