conch_runtime_pshaw/spawn/ast_impl/
pipeable.rs1use crate::env::FunctionEnvironment;
2use crate::spawn::{ExitStatus, Spawn};
3use crate::EXIT_SUCCESS;
4use conch_parser::ast;
5use futures_core::future::BoxFuture;
6use std::sync::Arc;
7
8impl<N, S, C, F, E> Spawn<E> for ast::PipeableCommand<N, S, C, Arc<F>>
9where
10 S: Spawn<E>,
11 C: Spawn<E, Error = S::Error>,
12 N: Sync + Clone,
13 F: Spawn<E, Error = S::Error> + Send + Sync + 'static,
14 E: ?Sized + Send + FunctionEnvironment,
15 E::FnName: From<N>,
16 E::Fn: From<Arc<dyn Spawn<E, Error = S::Error> + Send + Sync>>,
17{
18 type Error = S::Error;
19
20 fn spawn<'life0, 'life1, 'async_trait>(
21 &'life0 self,
22 env: &'life1 mut E,
23 ) -> BoxFuture<'async_trait, Result<BoxFuture<'static, ExitStatus>, Self::Error>>
24 where
25 'life0: 'async_trait,
26 'life1: 'async_trait,
27 Self: 'async_trait,
28 {
29 match self {
30 ast::PipeableCommand::Simple(s) => s.spawn(env),
31 ast::PipeableCommand::Compound(c) => c.spawn(env),
32 ast::PipeableCommand::FunctionDef(name, func) => Box::pin(async move {
33 env.set_function(name.clone().into(), E::Fn::from(func.clone()));
34 let ret: BoxFuture<'static, ExitStatus> = Box::pin(async { EXIT_SUCCESS });
35 Ok(ret)
36 }),
37 }
38 }
39}