1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::marker::PhantomData;

pub trait FactoryLayer<C, F> {
    type Factory;
    fn layer(&self, config: &C, inner: F) -> Self::Factory;
}

pub const fn layer_fn<C, FN>(f: FN) -> LayerFn<C, FN> {
    LayerFn {
        f,
        marker: PhantomData,
    }
}

pub struct LayerFn<C, FN> {
    f: FN,
    marker: PhantomData<fn(C)>,
}

impl<C, F, FN, O> FactoryLayer<C, F> for LayerFn<C, FN>
where
    FN: Fn(&C, F) -> O,
{
    type Factory = O;

    fn layer(&self, config: &C, inner: F) -> Self::Factory {
        (self.f)(config, inner)
    }
}