use bevy::prelude::*;
use crate::{
backend::AppBackend,
error::Error,
prelude::*,
};
pub trait Pipeline {
type Backend: for<'a> Backend<Self::Key<'a>> + FromWorld + Send + Sync + 'static;
type Format: Format;
type Key<'a>;
fn build(app: &mut App) {
let backend = Self::Backend::from_world(app.world_mut());
app.world_mut().insert_resource(AppBackend(backend));
}
fn key(&self) -> Self::Key<'_>;
fn capture(&self, builder: BuilderRef) -> Snapshot;
fn apply(&self, world: &mut World, snapshot: &Snapshot) -> Result<(), Error>;
}
pub trait AppPipelineExt {
fn init_pipeline<P: Pipeline>(&mut self) -> &mut Self;
}
impl AppPipelineExt for App {
fn init_pipeline<P: Pipeline>(&mut self) -> &mut Self {
P::build(self);
self
}
}