pub struct SerializableWorkflow<C, Input, M = ()> { /* private fields */ }Expand description
A workflow that can be serialized and deserialized.
This is a wrapper around Workflow that carries an internal TaskRegistry,
automatically populated during building. This enables serialization without
manually setting up a separate registry.
§Example
// Build a serializable workflow
let workflow = WorkflowBuilder::new(ctx)
.with_registry() // Enable serialization
.then("step1", |i: u32| async move { Ok(i + 1) })
.then("step2", |i: u32| async move { Ok(i * 2) })
.build()?;
// Serialize
let serialized = workflow.to_serializable();
let json = serde_json::to_string(&serialized)?;
// Deserialize (uses internal registry)
let deserialized: SerializedWorkflowState = serde_json::from_str(&json)?;
let restored = workflow.to_runnable(&deserialized)?;Implementations§
Source§impl<C, Input, M> SerializableWorkflow<C, Input, M>
impl<C, Input, M> SerializableWorkflow<C, Input, M>
Sourcepub fn workflow_id(&self) -> &str
pub fn workflow_id(&self) -> &str
Get the workflow ID.
Sourcepub fn definition_hash(&self) -> &str
pub fn definition_hash(&self) -> &str
Get the definition hash.
Sourcepub fn context(&self) -> &WorkflowContext<C, M>
pub fn context(&self) -> &WorkflowContext<C, M>
Get a reference to the context.
Sourcepub fn continuation(&self) -> &WorkflowContinuation
pub fn continuation(&self) -> &WorkflowContinuation
Get a reference to the continuation.
Sourcepub fn registry(&self) -> &TaskRegistry
pub fn registry(&self) -> &TaskRegistry
Get a reference to the internal task registry.
Sourcepub fn to_serializable(&self) -> SerializedWorkflowState
pub fn to_serializable(&self) -> SerializedWorkflowState
Convert to a serializable state representation.
Returns a SerializedWorkflowState that includes the workflow ID,
definition hash, and continuation structure. This can be serialized
and later deserialized to resume the workflow.
Sourcepub fn to_runnable(
&self,
state: &SerializedWorkflowState,
) -> Result<WorkflowContinuation, WorkflowError>
pub fn to_runnable( &self, state: &SerializedWorkflowState, ) -> Result<WorkflowContinuation, WorkflowError>
Convert a serialized workflow state to runnable using the internal registry.
§Errors
Returns WorkflowError::DefinitionMismatch if the definition hash doesn’t
match this workflow’s hash, indicating the serialized state was created with
a different workflow definition.
Returns WorkflowError::TaskNotFound if any task ID is not in the registry.