Skip to main content

cognis_core/compose/
passthrough.rs

1//! Identity runnable.
2
3use async_trait::async_trait;
4
5use crate::runnable::{Runnable, RunnableConfig};
6use crate::Result;
7
8/// Identity runnable: outputs its input unchanged. Generic over `I`,
9/// implementing `Runnable<I, I>` for any `I: Send + 'static`.
10#[derive(Debug, Default, Clone, Copy)]
11pub struct Passthrough;
12
13impl Passthrough {
14    /// Construct a `Passthrough`.
15    pub fn new() -> Self {
16        Self
17    }
18}
19
20#[async_trait]
21impl<I> Runnable<I, I> for Passthrough
22where
23    I: Send + 'static,
24{
25    async fn invoke(&self, input: I, _: RunnableConfig) -> Result<I> {
26        Ok(input)
27    }
28    fn name(&self) -> &str {
29        "Passthrough"
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[tokio::test]
38    async fn passes_through() {
39        let p = Passthrough::new();
40        let v: u32 = p.invoke(42, RunnableConfig::default()).await.unwrap();
41        assert_eq!(v, 42);
42    }
43}