use crate::plugin::{IdentityPlugin, Plugin, PluginStack};
use super::{LayerPlugin, ModelMarker};
#[derive(Debug)]
pub struct ModelPlugins<P>(pub(crate) P);
impl Default for ModelPlugins<IdentityPlugin> {
fn default() -> Self {
Self(IdentityPlugin)
}
}
impl ModelPlugins<IdentityPlugin> {
pub fn new() -> Self {
Self::default()
}
}
impl<P> ModelPlugins<P> {
pub fn push<NewPlugin: ModelMarker>(self, new_plugin: NewPlugin) -> ModelPlugins<PluginStack<NewPlugin, P>> {
ModelPlugins(PluginStack::new(new_plugin, self.0))
}
pub fn layer<L>(self, layer: L) -> ModelPlugins<PluginStack<LayerPlugin<L>, P>> {
ModelPlugins(PluginStack::new(LayerPlugin(layer), self.0))
}
}
impl<Ser, Op, T, InnerPlugin> Plugin<Ser, Op, T> for ModelPlugins<InnerPlugin>
where
InnerPlugin: Plugin<Ser, Op, T>,
{
type Output = InnerPlugin::Output;
fn apply(&self, input: T) -> Self::Output {
self.0.apply(input)
}
}
impl<InnerPlugin> ModelMarker for ModelPlugins<InnerPlugin> where InnerPlugin: ModelMarker {}