-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add Temporal Rust SDK references #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
donald-pinckney
merged 11 commits into
temporalio:main
from
wcygan:codex/init-rust-references
Jun 5, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
018f1f6
feat(rust): add Temporal Rust SDK references
wcygan 6a8ed99
remove cruft
wcygan 438daf6
official references link
wcygan ced6497
deslop
wcygan 31fce6f
deslop v2
wcygan 18d5669
docs(rust): mark Rust as Public Preview in SKILL.md reference list
wcygan c1ea293
docs(rust): label Rust as Public Preview in README support list
wcygan f0d5e09
docs(rust): add Public Preview NOTE callout to rust.md
wcygan 20544e7
docs(rust): point dependency guidance to official Rust SDK Quickstart
wcygan 02d2d4a
docs(rust): drop Skipping Activity timeouts pitfall
wcygan 57403ee
docs(rust): link directly to sdk-rust examples directory
wcygan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| # 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](https://docs.temporal.io/develop/rust) - Rust documentation hub. | ||
| - [Rust SDK Quickstart](https://docs.temporal.io/develop/rust/quickstart) - setup, dependencies, local dev server, and a complete hello-world example. | ||
| - [Workflow basics](https://docs.temporal.io/develop/rust/workflows/basics) - Workflow structs, `#[run]`, optional `#[init]`, and message handlers. | ||
| - [Activity basics](https://docs.temporal.io/develop/rust/activities/basics) - Activity macros, parameters, and Activity boundaries. | ||
| - [Worker processes](https://docs.temporal.io/develop/rust/workers/worker-process) - Worker setup, registration, and Task Queue polling. | ||
| - [Temporal Client](https://docs.temporal.io/develop/rust/client/temporal-client) - connecting to Temporal Service, starting Workflows, and fetching results. | ||
| - [docs.rs temporalio-sdk](https://docs.rs/temporalio-sdk/latest/temporalio_sdk/) - generated Rust API documentation. | ||
| - [sdk-rust examples](https://github.com/temporalio/sdk-rust/tree/main/crates/sdk/examples) - current example programs from the SDK repository. | ||
|
|
||
| ## Quick Demo of Temporal | ||
|
|
||
| **Add dependencies:** Follow the [official Rust SDK Quickstart](https://docs.temporal.io/develop/rust/quickstart) for the current `Cargo.toml` dependencies. | ||
|
|
||
| **src/activities.rs** - Activity definition: | ||
|
|
||
| ```rust | ||
| 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: | ||
|
|
||
| ```rust | ||
| 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: | ||
|
|
||
| ```rust | ||
| 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:** | ||
|
|
||
| 1. Start the dev server with `temporal server start-dev`. | ||
| 2. Run the Worker with `cargo run`. | ||
| 3. Start a Workflow Execution with the CLI: | ||
|
|
||
| ```sh | ||
| 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. | ||
|
|
||
| ```text | ||
| 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 | ||
|
|
||
| 1. **Calling I/O from a Workflow** - Put network, database, filesystem, process calls, and other side effects in Activities. | ||
| 2. **Mixing Worker and Workflow concerns** - Runtime setup, clients, secrets, environment config, and external logging sinks belong outside Workflow code. | ||
| 3. **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](https://github.com/temporalio/sdk-rust/tree/main/crates/sdk/examples). For SDK-neutral Temporal concepts, use the core references under `references/core/`. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.