1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! Flow orchestration for sequential and parallel execution.
//!
//! This module provides the core flow types for organizing nodes into
//! execution pipelines.
use crateFlowError;
use crateNode;
use join_all;
use Value;
/// A sequential execution pipeline for nodes.
///
/// `Flow` executes nodes one after another, passing the output of each node
/// as the input to the next node in the sequence.
///
/// # Example
///
/// ```rust
/// use rustyflow::{Flow, Node, FlowError};
/// use serde_json::{json, Value};
/// use async_trait::async_trait;
///
/// struct AddNode(i32);
///
/// #[async_trait]
/// impl Node for AddNode {
/// async fn call(&self, input: Value) -> Result<Value, FlowError> {
/// let num = input["value"].as_i64().unwrap_or(0) as i32;
/// Ok(json!({"value": num + self.0}))
/// }
/// }
///
/// # async fn example() -> Result<(), FlowError> {
/// let flow = Flow::new(vec![
/// Box::new(AddNode(5)),
/// Box::new(AddNode(10)),
/// ]);
///
/// let result = flow.execute(json!({"value": 0})).await?;
/// assert_eq!(result["value"], 15);
/// # Ok(())
/// # }
/// ```
/// A parallel execution pipeline for nodes.
///
/// `ParallelFlow` executes all nodes concurrently with the same input,
/// collecting their outputs into a JSON array.
///
/// # Example
///
/// ```rust
/// use rustyflow::{ParallelFlow, Node, FlowError};
/// use serde_json::{json, Value};
/// use async_trait::async_trait;
///
/// struct ProcessorNode {
/// name: String,
/// }
///
/// #[async_trait]
/// impl Node for ProcessorNode {
/// async fn call(&self, input: Value) -> Result<Value, FlowError> {
/// Ok(json!({"processor": self.name, "data": input}))
/// }
/// }
///
/// # async fn example() -> Result<(), FlowError> {
/// let parallel_flow = ParallelFlow::new(vec![
/// Box::new(ProcessorNode { name: "A".to_string() }),
/// Box::new(ProcessorNode { name: "B".to_string() }),
/// ]);
///
/// let result = parallel_flow.execute(json!({"value": 42})).await?;
/// // Result is an array with outputs from both processors
/// # Ok(())
/// # }
/// ```