use crate::host::command_trait::*;
use crate::host::scene_context::*;
use futures::prelude::*;
#[derive(Clone)]
pub struct PipeCommand<TSourceCommand, TTargetCommand>(TSourceCommand, TTargetCommand)
where
TSourceCommand: Command,
TTargetCommand: Command<Input=TSourceCommand::Output>;
impl<TSourceCommand, TTargetCommand> PipeCommand<TSourceCommand, TTargetCommand>
where
TSourceCommand: 'static + Command,
TTargetCommand: 'static + Command<Input=TSourceCommand::Output>,
{
#[inline]
pub fn new(source: TSourceCommand, target: TTargetCommand) -> Self {
Self(source, target)
}
}
impl<TSourceCommand, TTargetCommand> Command for PipeCommand<TSourceCommand, TTargetCommand>
where
TSourceCommand: 'static + Command,
TTargetCommand: 'static + Command<Input=TSourceCommand::Output>,
{
type Input = TSourceCommand::Input;
type Output = TTargetCommand::Output;
#[inline]
fn run<'a>(&'a self, input: impl 'static + Send + Stream<Item=Self::Input>, context: SceneContext) -> impl 'a + Send + Future<Output=()> {
let source_cmd = self.0.clone();
let target_cmd = self.1.clone();
async move {
let pipe_stream = context.spawn_command(source_cmd, input);
if let Ok(pipe_stream) = pipe_stream {
target_cmd.run(pipe_stream, context).await;
}
}
}
}