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>) -> Command
pub fn updates(self, updates: Vec<StateUpdate>) -> Command
Add multiple state updates
Sourcepub fn goto(self, node: impl Into<String>) -> Command
pub fn goto(self, node: impl Into<String>) -> Command
Set control flow to jump to a specific node
Sourcepub fn send(targets: Vec<SendCommand>) -> Command
pub fn send(targets: Vec<SendCommand>) -> Command
Set control flow to create parallel branches (MapReduce)
Sourcepub fn just_update(key: impl Into<String>, value: Value) -> Command
pub fn just_update(key: impl Into<String>, value: Value) -> Command
Create a command that just updates state (continues by default)
Sourcepub fn just_goto(node: impl Into<String>) -> Command
pub fn just_goto(node: impl Into<String>) -> Command
Create a command that just controls flow (no state update)
Sourcepub fn just_return() -> Command
pub fn just_return() -> Command
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<Command, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Command, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Command
impl Serialize for Command
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage