Skip to main content

synaptic_runnables/
passthrough.rs

1use async_trait::async_trait;
2use serde_json::Value;
3use synaptic_core::{RunnableConfig, SynapticError};
4
5use crate::assign::RunnableAssign;
6use crate::runnable::BoxRunnable;
7use crate::Runnable;
8
9/// Passes the input through unchanged. Useful in parallel compositions
10/// where one branch should preserve the original input.
11#[derive(Debug, Clone, Copy, Default)]
12pub struct RunnablePassthrough;
13
14impl RunnablePassthrough {
15    /// Create a `RunnableAssign` that passes input through and merges additional computed keys.
16    pub fn assign(branches: Vec<(String, BoxRunnable<Value, Value>)>) -> RunnableAssign {
17        RunnableAssign::new(branches)
18    }
19}
20
21#[async_trait]
22impl<T> Runnable<T, T> for RunnablePassthrough
23where
24    T: Send + Sync + 'static,
25{
26    async fn invoke(&self, input: T, _config: &RunnableConfig) -> Result<T, SynapticError> {
27        Ok(input)
28    }
29}