pub struct Command {
pub updates: Vec<StateUpdate>,
pub control: ControlFlow,
}Expand description
Command returned by node functions
A Command encapsulates both state updates and control flow decisions. This allows nodes to update state AND determine where to go next in a single return value.
§Example
ⓘ
// Update state and continue to next node
let cmd = Command::new()
.update("result", json!("processed"))
.continue_();
// Update state and jump to specific node
let cmd = Command::new()
.update("classification", json!("type_a"))
.goto("handle_a");
// End execution with final state
let cmd = Command::new()
.update("final_result", json!("done"))
.return_();
// Create parallel branches for MapReduce
let cmd = Command::send(vec![
SendCommand::new("process", json!({"item": 1})),
SendCommand::new("process", json!({"item": 2})),
]);Fields§
§updates: Vec<StateUpdate>State updates to apply
control: ControlFlowControl flow directive
Implementations§
Source§impl Command
impl Command
Sourcepub fn updates(self, updates: Vec<StateUpdate>) -> Self
pub fn updates(self, updates: Vec<StateUpdate>) -> Self
Add multiple state updates
Sourcepub fn send(targets: Vec<SendCommand>) -> Self
pub fn send(targets: Vec<SendCommand>) -> Self
Set control flow to create parallel branches (MapReduce)
Sourcepub fn just_update(key: impl Into<String>, value: Value) -> Self
pub fn just_update(key: impl Into<String>, value: Value) -> Self
Create a command that just updates state (continues by default)
Sourcepub fn just_goto(node: impl Into<String>) -> Self
pub fn just_goto(node: impl Into<String>) -> Self
Create a command that just controls flow (no state update)
Sourcepub fn just_return() -> Self
pub fn just_return() -> Self
Create a command that ends execution
Sourcepub fn goto_target(&self) -> Option<&str>
pub fn goto_target(&self) -> Option<&str>
Get the target node if this is a goto command
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Command
impl<'de> Deserialize<'de> for Command
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Command
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnsafeUnpin for Command
impl UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more