rhai_process/
pipe_builder.rs

1use crate::command_builder::CommandBuilder;
2use crate::command_spec::CommandSpec;
3use crate::config::Config;
4use crate::pipeline_executor::PipelineExecutor;
5use crate::util::ensure_same_config;
6use crate::RhaiResult;
7use std::sync::Arc;
8
9#[derive(Clone, Debug)]
10pub struct PipeBuilder {
11    pub(crate) config: Arc<Config>,
12    pub(crate) commands: Vec<CommandSpec>,
13}
14
15impl PipeBuilder {
16    pub(crate) fn from_single(config: Arc<Config>, command: CommandSpec) -> Self {
17        Self {
18            config,
19            commands: vec![command],
20        }
21    }
22
23    pub(crate) fn push_command(&mut self, spec: CommandSpec) {
24        self.commands.push(spec);
25    }
26
27    pub(crate) fn into_executor(self) -> PipelineExecutor {
28        PipelineExecutor::new(self.config, self.commands)
29    }
30
31    pub fn pipe(mut self, next: CommandBuilder) -> RhaiResult<Self> {
32        ensure_same_config(&self.config, &next.config)?;
33        self.push_command(next.command);
34        Ok(self)
35    }
36
37    pub fn build(self) -> PipelineExecutor {
38        self.into_executor()
39    }
40}