use std::marker::PhantomData;
use tower::Layer;
use super::{HttpMarker, ModelMarker, Plugin};
pub struct LayerPlugin<L>(pub L);
impl<Ser, Op, S, L> Plugin<Ser, Op, S> for LayerPlugin<L>
where
L: Layer<S>,
{
type Output = L::Service;
fn apply(&self, svc: S) -> Self::Output {
self.0.layer(svc)
}
}
impl<L> HttpMarker for LayerPlugin<L> {}
impl<L> ModelMarker for LayerPlugin<L> {}
pub struct PluginLayer<Ser, Op, Pl> {
plugin: Pl,
_ser: PhantomData<Ser>,
_op: PhantomData<Op>,
}
impl<S, Ser, Op, Pl> Layer<S> for PluginLayer<Ser, Op, Pl>
where
Pl: Plugin<Ser, Op, S>,
{
type Service = Pl::Output;
fn layer(&self, inner: S) -> Self::Service {
self.plugin.apply(inner)
}
}
impl<Pl> PluginLayer<(), (), Pl> {
pub fn new<Ser, Op>(plugin: Pl) -> PluginLayer<Ser, Op, Pl> {
PluginLayer {
plugin,
_ser: PhantomData,
_op: PhantomData,
}
}
}