juncture_core/send.rs
1//! Send API for dynamic fan-out
2//!
3//! The Send API allows nodes to dynamically create multiple parallel tasks,
4//! each with its own state snapshot.
5
6use crate::State;
7
8/// Dynamic fan-out target
9///
10/// Represents a single task in a dynamic fan-out operation. Each Send target
11/// specifies which node to execute and provides a custom state for that task.
12///
13/// # Examples
14///
15/// ```ignore
16/// use juncture_core::{Send, State, command::SendTarget};
17/// use serde_json::json;
18///
19/// struct MyState;
20/// impl State for MyState {
21/// type Update = MyStateUpdate;
22/// }
23///
24/// struct MyStateUpdate;
25///
26/// // Create a send target with custom state
27/// let send = Send {
28/// node: "worker".to_string(),
29/// state: MyState { /* ... */ },
30/// };
31/// ```
32#[derive(Debug)]
33pub struct Send<S: State> {
34 /// Target node name to execute
35 pub node: String,
36
37 /// Custom state for this task (overrides current state)
38 pub state: S,
39}
40
41impl<S: State + serde::Serialize> From<Send<S>> for crate::command::SendTarget {
42 fn from(send: Send<S>) -> Self {
43 Self {
44 node: send.node,
45 // Convert state to JSON value
46 state: serde_json::to_value(send.state)
47 .expect("state must be serializable for Send API"),
48 timeout: None,
49 }
50 }
51}
52
53// Rust guideline compliant 2026-05-20