metrics_prometheus/recorder/
layer.rs1pub use metrics_util::layers::Layer;
6
7#[derive(Clone, Copy, Debug)]
12pub struct Identity;
13
14impl<R> Layer<R> for Identity {
15 type Output = R;
16
17 #[expect(clippy::renamed_function_params, reason = "impl related")]
18 fn layer(&self, itself: R) -> R {
19 itself
20 }
21}
22
23#[derive(Clone, Copy, Debug)]
29pub struct Stack<Head = Identity, Tail = Identity>(Head, Tail);
30
31impl Stack {
32 #[must_use]
37 pub const fn identity() -> Self {
38 Self(Identity, Identity)
39 }
40}
41
42impl<H, T> Stack<H, T> {
43 #[must_use]
48 pub const fn push<R, L: Layer<R>>(self, layer: L) -> Stack<L, Self> {
49 Stack(layer, self)
50 }
51}
52
53#[warn(clippy::missing_trait_methods)]
54impl<R, H, T> Layer<R> for Stack<H, T>
55where
56 H: Layer<<T as Layer<R>>::Output>,
57 T: Layer<R>,
58{
59 type Output = H::Output;
60
61 fn layer(&self, inner: R) -> Self::Output {
62 self.0.layer(self.1.layer(inner))
63 }
64}