use bevy::prelude::*;
use bevy::ecs::system::{Adapt, AdapterSystem, RunSystemError};
pub fn with_input<S, I, O, M>(input: I, system: S) -> AdapterSystem<InputAdapter<I>, S::System>
where
S: IntoSystem<In<I>, O, M>,
I: Sync + Send + Clone + 'static,
{
let system = IntoSystem::into_system(system);
let name = format!("with_input({})", system.name());
AdapterSystem::new(InputAdapter(input), system, name.into())
}
#[doc(hidden)]
pub struct InputAdapter<I>(I);
impl<'l, S> Adapt<S> for InputAdapter<SystemIn<'l, S>>
where
S: System,
SystemIn<'l, S>: Sync + Send + Clone + 'static,
{
type In = ();
type Out = S::Out;
fn adapt(
&mut self,
_input: (),
run_system: impl FnOnce(SystemIn<'_, S>) -> Result<S::Out, RunSystemError>,
) -> Result<S::Out, RunSystemError>
{
run_system(self.0.clone())
}
}