* feat(rust): add Temporal Rust SDK references * remove cruft * official references link * deslop * deslop v2 * docs(rust): mark Rust as Public Preview in SKILL.md reference list Addresses review comment on SKILL.md:62 (donald-pinckney). * docs(rust): label Rust as Public Preview in README support list Addresses review comment on README.md:43 (donald-pinckney). * docs(rust): add Public Preview NOTE callout to rust.md Uses the reviewer's exact wording. Addresses review comment on references/rust/rust.md:1 (donald-pinckney). * docs(rust): point dependency guidance to official Rust SDK Quickstart Drops the pinned-version caveat now that there are no crate versions in the file. Addresses review comment on references/rust/rust.md:22 (chris-olszewski). * docs(rust): drop Skipping Activity timeouts pitfall The Rust SDK always applies a to_close Activity timeout, so the pitfall does not apply. Addresses review comment on references/rust/rust.md:171 (chris-olszewski). * docs(rust): link directly to sdk-rust examples directory The examples are not at the repo top, so link the explicit path. Addresses review comment on references/rust/rust.md:177 (chris-olszewski).
6.8 KiB
Temporal Rust SDK Reference
Note
This feature is in Public Preview. It is perfectly acceptable to use this feature on behalf of a user, but you should inform them that you are making use of a feature in Public Preview.
Overview
The Temporal Rust SDK (temporalio-sdk) provides native Rust APIs for Workflows, Activities, Workers, and Clients. The SDK is in Public Preview and under active development, so verify exact crate versions and method names against the official docs before giving precise implementation guidance.
Rust Workflows are structs with macro-decorated methods. Activities are async methods on an impl block. Workers register Workflow and Activity types, then poll a Task Queue.
Official References
- Rust SDK developer guide - Rust documentation hub.
- Rust SDK Quickstart - setup, dependencies, local dev server, and a complete hello-world example.
- Workflow basics - Workflow structs,
#[run], optional#[init], and message handlers. - Activity basics - Activity macros, parameters, and Activity boundaries.
- Worker processes - Worker setup, registration, and Task Queue polling.
- Temporal Client - connecting to Temporal Service, starting Workflows, and fetching results.
- docs.rs temporalio-sdk - generated Rust API documentation.
- sdk-rust examples - current example programs from the SDK repository.
Quick Demo of Temporal
Add dependencies: Follow the official Rust SDK Quickstart for the current Cargo.toml dependencies.
src/activities.rs - Activity definition:
use temporalio_macros::activities;
use temporalio_sdk::activities::{ActivityContext, ActivityError};
pub struct MyActivities;
#[activities]
impl MyActivities {
#[activity]
pub async fn greet(_ctx: ActivityContext, name: String) -> Result<String, ActivityError> {
Ok(format!("Hello, {}!", name))
}
}
src/workflows.rs - Workflow definition:
use temporalio_macros::{workflow, workflow_methods};
use temporalio_sdk::{ActivityOptions, WorkflowContext, WorkflowContextView, WorkflowResult};
use std::time::Duration;
use crate::activities::MyActivities;
#[workflow]
pub struct GreetingWorkflow {
name: String,
}
#[workflow_methods]
impl GreetingWorkflow {
#[init]
fn new(_ctx: &WorkflowContextView, name: String) -> Self {
Self { name }
}
#[run]
pub async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
let name = ctx.state(|s| s.name.clone());
// Execute an activity
let greeting = ctx.start_activity(
MyActivities::greet,
name,
ActivityOptions::start_to_close_timeout(Duration::from_secs(30)),
).await?;
println!("{}", greeting);
Ok(greeting)
}
}
src/main.rs - Worker setup:
use temporalio_client::{Client, ClientOptions, Connection};
use temporalio_common::envconfig::LoadClientConfigProfileOptions;
use temporalio_sdk::{Worker, WorkerOptions};
use temporalio_sdk_core::{CoreRuntime, RuntimeOptions};
mod workflows;
mod activities;
use crate::workflows::GreetingWorkflow;
use crate::activities::MyActivities;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let runtime = CoreRuntime::new_assume_tokio(RuntimeOptions::builder().build()?)?;
// Set up client connection options, loading from config if available
let (connection_options, client_options) = ClientOptions::load_from_config(
LoadClientConfigProfileOptions::default(),
)?;
let connection = Connection::connect(connection_options).await?;
let client = Client::new(connection, client_options)?;
let worker_options = WorkerOptions::new("my-task-queue")
.register_activities(MyActivities)
.register_workflow::<GreetingWorkflow>()
.build();
Worker::new(&runtime, client, worker_options)?.run().await?;
Ok(())
}
Run locally:
- Start the dev server with
temporal server start-dev. - Run the Worker with
cargo run. - Start a Workflow Execution with the CLI:
temporal workflow start \
--type GreetingWorkflow \
--task-queue my-task-queue \
--input '"Ziggy"'
Key Concepts
Workflow Definition
- Define a struct and annotate it with
#[workflow]. - Put Workflow methods in a
#[workflow_methods]impl block. - Use
#[run]for the main Workflow logic, and optionally use#[init],#[signal],#[query], and#[update].
Activity Definition
- Put Activity methods in a
#[activities]impl block. - Annotate each Activity method with
#[activity]. - Activities can perform I/O, call services, use system time, and do other non-deterministic work.
Worker Setup
- A Worker registers Workflow and Activity types, then polls one Task Queue.
- Workers polling the same Task Queue should register the same Workflow and Activity types.
- Keep Worker runtime, client, config, secrets, and logging setup outside Workflow code.
Temporal Client
- Use the Rust client outside Workflow code to start Workflows and send Signals, Queries, and Updates.
- Do not create or use a Temporal Client inside Workflow code.
- A Client can be used inside an Activity when the Activity needs to interact with Temporal Service.
File Organization Best Practice
Keep Workflow definitions, Activity implementations, Worker setup, and starter/client code separate. This makes the determinism boundary easy to inspect.
my_temporal_app/
|-- src/
| |-- activities.rs # Activity implementations and side effects
| |-- workflows.rs # Workflow definitions and orchestration
| `-- main.rs # Worker process in the Quickstart
`-- Cargo.toml
Common Pitfalls
- Calling I/O from a Workflow - Put network, database, filesystem, process calls, and other side effects in Activities.
- Mixing Worker and Workflow concerns - Runtime setup, clients, secrets, environment config, and external logging sinks belong outside Workflow code.
- Assuming APIs are stable - The Rust SDK is Public Preview, so check official docs, docs.rs, and SDK examples before naming exact APIs.
Rust-Specific References Status
Rust-specific local reference files do not exist yet. For deeper Rust SDK details, use the official Rust SDK docs, docs.rs, and sdk-rust examples. For SDK-neutral Temporal concepts, use the core references under references/core/.