Expand description
§Node Flow
Node Flow is runtime-agnostic, composable, asynchronous node-based framework for building structured and reusable data processing pipelines, workflows, or control flows.
The core idea is that each node represents a self-contained asynchronous operation, and flows define how multiple nodes are composed and executed.
§Key concepts
Node- the core building block, representing an async unit of work.NodeOutput- output type used by nodes to signal success or soft failure.Flows- structures that determine execution order and behavior.Context system- flows and nodes can restrict the context to ensure that it can perform functions such as:- sharing a mutable state
- context branching/joining
- task spawning
Description- describes the structure of a flow, which can then be used for visualization.
§Examples
use node_flow::node::{Node, NodeOutput};
use node_flow::flows::SequentialFlow;
// Example node
#[derive(Clone)]
struct AddOne;
struct ExampleCtx;
impl<Ctx: Send> Node<u8, NodeOutput<u8>, (), Ctx> for AddOne {
async fn run(&mut self, input: u8, _: &mut Ctx) -> Result<NodeOutput<u8>, ()> {
Ok(NodeOutput::Ok(input + 1))
}
}
async fn main() {
let mut flow = SequentialFlow::<u8, u8, (), _>::builder()
.add_node(AddOne)
.add_node(AddOne)
.add_node(AddOne)
.build();
let mut ctx = ExampleCtx;
let result = flow.run(5u8, &mut ctx).await;
assert_eq!(result, Ok(NodeOutput::Ok(8)));
}§When to use Node Flow
Use this crate when you need:
- Composable async control flows (e.g., fallback chains, parallel processing).
- Declarative and type-safe node composition.
- Inspectable or visualizable flow structures.
Modules§
- context
- This module contains basic traits that should be implemented for node context.
- describe
- This module contains all the necessary components for describing the structure of a flow.
- flows
- This module contains all the different types of flows.
- node
- This module contains the
Nodetrait and everything related to it.
Macros§
- impl_
node_ output - Implements the
Nodetrait for a type whose output needs to be wrapped inNodeOutput. - node
- A helper macro for declaring
impl Nodereturn type.