floxide_core/
composite.rs1use crate::{context::Context, error::FloxideError, Node, Transition, Workflow, WorkflowCtx};
2use async_trait::async_trait;
3use serde::{de::DeserializeOwned, Serialize};
4use std::fmt::Debug;
5#[derive(Clone, Debug)]
7pub struct CompositeNode<C: Context, W> {
8 ctx: WorkflowCtx<C>,
9 workflow: W,
10}
11
12impl<C: Context, W> CompositeNode<C, W> {
13 pub fn new(workflow: W, ctx: &WorkflowCtx<C>) -> Self {
14 CompositeNode {
15 ctx: ctx.clone(),
16 workflow,
17 }
18 }
19}
20
21#[async_trait]
22impl<C: Context, W> Node<C> for CompositeNode<C, W>
23where
24 C: Serialize + DeserializeOwned + Debug + Clone + Send + Sync,
25 W: Workflow<C> + Clone + Send + Sync,
26 W::Input: Send + Sync,
27 W::Output: Send + Sync,
28{
29 type Input = W::Input;
30 type Output = W::Output;
31
32 async fn process(
33 &self,
34 ctx: &C,
35 input: Self::Input,
36 ) -> Result<Transition<Self::Output>, FloxideError> {
37 let mut w_ctx = self.ctx.clone();
38 w_ctx.store = ctx.clone();
39 let out = self.workflow.run(&w_ctx, input).await?;
40 Ok(Transition::Next(out))
41 }
42}