Skip to content

Commit 16993b6

Browse files
authored
src/lib: Add #![deny(missing_docs)] (#84)
Enforces documentation comments on every public type. Signed-off-by: Max Inden <[email protected]>
1 parent f5018cf commit 16993b6

File tree

10 files changed

+51
-3
lines changed

10 files changed

+51
-3
lines changed

src/encoding/text.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ use std::ops::Deref;
4040

4141
pub 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.
4345
pub fn encode<W, M>(writer: &mut W, registry: &Registry<M>) -> Result<(), std::io::Error>
4446
where
4547
W: Write,
@@ -92,7 +94,9 @@ where
9294
Ok(())
9395
}
9496

97+
/// OpenMetrics text encoding for a value.
9598
pub 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]
309314
pub 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]
349355
pub 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]
367374
pub 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.
393400
pub 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`].
411421
pub trait SendSyncEncodeMetric: EncodeMetric + Send + Sync {}
412422

413423
impl<T: EncodeMetric + Send + Sync> SendSyncEncodeMetric for T {}

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#![forbid(unsafe_code)]
2-
#![deny(unused)]
31
#![deny(dead_code)]
2+
#![deny(missing_docs)]
3+
#![deny(unused)]
4+
#![forbid(unsafe_code)]
45
#![warn(missing_debug_implementations)]
56

67
//! Client library implementation of the [Open Metrics

src/metrics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ pub mod info;
99

1010
/// A metric that is aware of its Open Metrics metric type.
1111
pub trait TypedMetric {
12+
/// The OpenMetrics metric type.
1213
const TYPE: MetricType = MetricType::Unknown;
1314
}
1415

16+
/// OpenMetrics metric type.
1517
#[derive(Clone, Copy, Debug)]
18+
#[allow(missing_docs)]
1619
pub enum MetricType {
1720
Counter,
1821
Gauge,

src/metrics/counter.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct Counter<N = u64, A = AtomicU64> {
4545
phantom: PhantomData<N>,
4646
}
4747

48+
/// Open Metrics [`Counter`] to measure discrete events.
4849
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
4950
#[derive(Debug)]
5051
pub struct Counter<N = u32, A = AtomicU32> {
@@ -99,11 +100,15 @@ impl<N, A: Atomic<N>> Counter<N, A> {
99100
}
100101
}
101102

103+
/// Atomic operations for a [`Counter`] value store.
102104
pub trait Atomic<N> {
105+
/// Increase the value by `1`.
103106
fn inc(&self) -> N;
104107

108+
/// Increase the value.
105109
fn inc_by(&self, v: N) -> N;
106110

111+
/// Get the the value.
107112
fn get(&self) -> N;
108113
}
109114

src/metrics/exemplar.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::sync::atomic::AtomicU32;
1212
use std::sync::atomic::AtomicU64;
1313
use std::sync::Arc;
1414

15+
/// An OpenMetrics exemplar.
1516
#[derive(Debug)]
1617
pub struct Exemplar<S, V> {
1718
pub(crate) label_set: S,
@@ -36,6 +37,8 @@ pub struct CounterWithExemplar<S, N = u64, A = AtomicU64> {
3637
pub(crate) inner: Arc<RwLock<CounterWithExemplarInner<S, N, A>>>,
3738
}
3839

40+
/// Open Metrics [`Counter`] with an [`Exemplar`] to both measure discrete
41+
/// events and track references to data outside of the metric set.
3942
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
4043
#[derive(Debug)]
4144
pub struct CounterWithExemplar<S, N = u32, A = AtomicU32> {
@@ -50,6 +53,7 @@ impl<S, N, A> Clone for CounterWithExemplar<S, N, A> {
5053
}
5154
}
5255

56+
/// An OpenMetrics [`Counter`] in combination with an OpenMetrics [`Exemplar`].
5357
#[derive(Debug)]
5458
pub struct CounterWithExemplarInner<S, N, A> {
5559
pub(crate) exemplar: Option<Exemplar<S, N>>,
@@ -132,13 +136,15 @@ impl<S> Clone for HistogramWithExemplars<S> {
132136
}
133137
}
134138

139+
/// An OpenMetrics [`Histogram`] in combination with an OpenMetrics [`Exemplar`].
135140
#[derive(Debug)]
136141
pub struct HistogramWithExemplarsInner<S> {
137142
pub(crate) exemplars: HashMap<usize, Exemplar<S, f64>>,
138143
pub(crate) histogram: Histogram,
139144
}
140145

141146
impl<S> HistogramWithExemplars<S> {
147+
/// Create a new [`HistogramWithExemplars`].
142148
pub fn new(buckets: impl Iterator<Item = f64>) -> Self {
143149
Self {
144150
inner: Arc::new(RwLock::new(HistogramWithExemplarsInner {
@@ -148,6 +154,8 @@ impl<S> HistogramWithExemplars<S> {
148154
}
149155
}
150156

157+
/// Observe the given value, optionally providing a label set and thus
158+
/// setting the [`Exemplar`] value.
151159
pub fn observe(&self, v: f64, label_set: Option<S>) {
152160
let mut inner = self.inner.write();
153161
let bucket = inner.histogram.observe_and_bucket(v);

src/metrics/family.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub struct Family<S, M, C = fn() -> M> {
136136
/// let metric = Family::<(), Histogram, CustomBuilder>::new_with_constructor(custom_builder);
137137
/// ```
138138
pub trait MetricConstructor<M> {
139+
/// Create a new instance of the metric type.
139140
fn new_metric(&self) -> M;
140141
}
141142

src/metrics/gauge.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct Gauge<N = u64, A = AtomicU64> {
4545
phantom: PhantomData<N>,
4646
}
4747

48+
/// Open Metrics [`Gauge`] to record current measurements.
4849
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
4950
#[derive(Debug)]
5051
pub struct Gauge<N = u32, A = AtomicU32> {
@@ -110,17 +111,24 @@ impl<N, A: Atomic<N>> Gauge<N, A> {
110111
}
111112
}
112113

114+
/// Atomic operations for a [`Gauge`] value store.
113115
pub trait Atomic<N> {
116+
/// Increase the value by `1`.
114117
fn inc(&self) -> N;
115118

119+
/// Increase the value.
116120
fn inc_by(&self, v: N) -> N;
117121

122+
/// Decrease the value by `1`.
118123
fn dec(&self) -> N;
119124

125+
/// Decrease the value.
120126
fn dec_by(&self, v: N) -> N;
121127

128+
/// Set the value.
122129
fn set(&self, v: N) -> N;
123130

131+
/// Get the value.
124132
fn get(&self) -> N;
125133
}
126134

src/metrics/histogram.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub(crate) struct Inner {
5454
}
5555

5656
impl Histogram {
57+
/// Create a new [`Histogram`].
5758
pub fn new(buckets: impl Iterator<Item = f64>) -> Self {
5859
Self {
5960
inner: Arc::new(RwLock::new(Inner {
@@ -68,6 +69,7 @@ impl Histogram {
6869
}
6970
}
7071

72+
/// Observe the given value.
7173
pub fn observe(&self, v: f64) {
7274
self.observe_and_bucket(v);
7375
}
@@ -110,13 +112,15 @@ impl TypedMetric for Histogram {
110112
const TYPE: MetricType = MetricType::Histogram;
111113
}
112114

115+
/// Exponential bucket distribution.
113116
pub fn exponential_buckets(start: f64, factor: f64, length: u16) -> impl Iterator<Item = f64> {
114117
iter::repeat(())
115118
.enumerate()
116119
.map(move |(i, _)| start * factor.powf(i as f64))
117120
.take(length.into())
118121
}
119122

123+
/// Linear bucket distribution.
120124
pub fn linear_buckets(start: f64, width: f64, length: u16) -> impl Iterator<Item = f64> {
121125
iter::repeat(())
122126
.enumerate()

src/metrics/info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::metrics::{MetricType, TypedMetric};
1616
pub struct Info<S>(pub(crate) S);
1717

1818
impl<S> Info<S> {
19+
/// Create [`Info`] metric with the provided label set.
1920
pub fn new(label_set: S) -> Self {
2021
Self(label_set)
2122
}

src/registry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ impl<M> Registry<M> {
238238
.expect("sub_registries not to be empty.")
239239
}
240240

241+
/// [`Iterator`] over all metrics registered with the [`Registry`].
241242
pub fn iter(&self) -> RegistryIterator<M> {
242243
let metrics = self.metrics.iter();
243244
let sub_registries = self.sub_registries.iter();
@@ -297,6 +298,7 @@ impl From<Prefix> for String {
297298
}
298299
}
299300

301+
/// OpenMetrics metric descriptor.
300302
#[derive(Debug)]
301303
pub struct Descriptor {
302304
name: String,
@@ -306,18 +308,22 @@ pub struct Descriptor {
306308
}
307309

308310
impl Descriptor {
311+
/// Returns the name of the OpenMetrics metric [`Descriptor`].
309312
pub fn name(&self) -> &str {
310313
&self.name
311314
}
312315

316+
/// Returns the help text of the OpenMetrics metric [`Descriptor`].
313317
pub fn help(&self) -> &str {
314318
&self.help
315319
}
316320

321+
/// Returns the unit of the OpenMetrics metric [`Descriptor`].
317322
pub fn unit(&self) -> &Option<Unit> {
318323
&self.unit
319324
}
320325

326+
/// Returns the label set of the OpenMetrics metric [`Descriptor`].
321327
pub fn labels(&self) -> &[(Cow<'static, str>, Cow<'static, str>)] {
322328
&self.labels
323329
}
@@ -327,6 +333,7 @@ impl Descriptor {
327333
///
328334
/// See [`Unit::Other`] to specify alternative units.
329335
#[derive(Debug)]
336+
#[allow(missing_docs)]
330337
pub enum Unit {
331338
Amperes,
332339
Bytes,

0 commit comments

Comments
 (0)