pub use metrics_util::layers::Layer;
#[derive(Clone, Copy, Debug)]
pub struct Identity;
impl<R> Layer<R> for Identity {
type Output = R;
fn layer(&self, itself: R) -> R {
itself
}
}
#[derive(Clone, Copy, Debug)]
pub struct Stack<Head = Identity, Tail = Identity>(Head, Tail);
impl Stack {
#[must_use]
pub const fn identity() -> Self {
Self(Identity, Identity)
}
}
impl<H, T> Stack<H, T> {
#[must_use]
pub const fn push<R, L: Layer<R>>(self, layer: L) -> Stack<L, Self> {
Stack(layer, self)
}
}
#[warn(clippy::missing_trait_methods)]
impl<R, H, T> Layer<R> for Stack<H, T>
where
H: Layer<<T as Layer<R>>::Output>,
T: Layer<R>,
{
type Output = H::Output;
fn layer(&self, inner: R) -> Self::Output {
self.0.layer(self.1.layer(inner))
}
}