Skip to main content

SerializableWorkflow

Struct SerializableWorkflow 

Source
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>

Source

pub fn workflow_id(&self) -> &str

Get the workflow ID.

Source

pub fn definition_hash(&self) -> &DefinitionHash

Get the definition hash.

Source

pub fn workflow(&self) -> &Workflow<C, Input, M>

Get a reference to the inner workflow.

Source

pub fn context(&self) -> &WorkflowContext<C, M>

Get a reference to the context.

Source

pub fn codec(&self) -> &Arc<C>

Get a reference to the codec.

Source

pub fn continuation(&self) -> &WorkflowContinuation

Get a reference to the continuation.

Source

pub fn metadata(&self) -> &Arc<M>

Get a reference to the metadata.

Source

pub fn registry(&self) -> &TaskRegistry

Get a reference to the internal task registry.

Source

pub fn into_parts(self) -> (WorkflowContinuation, TaskRegistry)

Consume the workflow and return its continuation tree and task registry.

Useful for inlining this workflow as a child inside another workflow while merging task registries.

Source

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.

Source

pub fn to_runnable( &self, state: &SerializedWorkflowState, ) -> Result<WorkflowContinuation, BuildError>

Convert a serialized workflow state to runnable using the internal registry.

§Errors

Returns BuildError::DefinitionMismatch if the definition hash doesn’t match this workflow’s hash, indicating the serialized state was created with a different workflow definition.

Returns BuildError::TaskNotFound if any task ID is not in the registry.

Methods from Deref<Target = Workflow<C, Input, M>>§

Source

pub fn workflow_id(&self) -> &str

Get the workflow name (human-readable).

Source

pub fn definition_hash(&self) -> &DefinitionHash

Get the definition hash.

This hash is computed from the workflow’s continuation structure and serves as a version identifier. It can be used to detect when a serialized workflow state was created with a different workflow definition.

Source

pub fn context(&self) -> &WorkflowContext<C, M>

Get a reference to the context of this workflow.

Source

pub fn codec(&self) -> &Arc<C>

Get a reference to the codec used by this workflow.

Source

pub fn continuation(&self) -> &WorkflowContinuation

Get a reference to the continuation of this workflow.

Source

pub fn task_index(&self) -> &TaskIndex

Borrow the TaskId → metadata index. Built once at build time.

Source

pub fn task_index_arc(&self) -> Arc<TaskIndex>

Clone the shared Arc<TaskIndex> — for callers (FFI / runtime) that want to hold onto the index alongside the continuation.

Source

pub fn metadata(&self) -> &Arc<M>

Get a reference to the metadata attached to this workflow.

Source

pub fn iter_nodes(&self) -> NodeIter<'_>

Returns a lazy iterator over all nodes in topological (execution) order.

Convenience wrapper around WorkflowContinuation::iter_nodes.

Trait Implementations§

Source§

impl<C, Input, M> Deref for SerializableWorkflow<C, Input, M>

Source§

type Target = Workflow<C, Input, M>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<C, Input, M = ()> !RefUnwindSafe for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M = ()> !UnwindSafe for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M> Freeze for SerializableWorkflow<C, Input, M>

§

impl<C, Input, M> Send for SerializableWorkflow<C, Input, M>
where Input: Send, C: Sync + Send, M: Sync + Send,

§

impl<C, Input, M> Sync for SerializableWorkflow<C, Input, M>
where Input: Sync, C: Sync + Send, M: Sync + Send,

§

impl<C, Input, M> Unpin for SerializableWorkflow<C, Input, M>
where Input: Unpin,

§

impl<C, Input, M> UnsafeUnpin for SerializableWorkflow<C, Input, M>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.