Skip to content

Commit a692fdd

Browse files
authored
Add Rust SDK examples and activity definition code tabs (#4565)
* Add Rust SDK examples and activity definition code tabs * Add WorkflowContext import to Rust workflow definition
1 parent 201a58f commit a692fdd

2 files changed

Lines changed: 163 additions & 0 deletions

File tree

docs/encyclopedia/activities/activity-definition.mdx

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,146 @@ Temporal documentation aims to be explicit and differentiate between them.
3333
An Activity Definition is the code that defines the constraints of an [Activity Task Execution](/tasks#activity-task-execution).
3434
Activities encapsulate business logic that is prone to failure, allowing for automatic retries when issues occur.
3535

36+
Below are examples of basic Activity Definitions across supported SDKs.
37+
38+
<Tabs groupId="basic-activity-definition" queryString>
39+
<TabItem value="go" label="Go">
40+
41+
**[Activity Definition in Go](/develop/go/activities/basics)**
42+
43+
```go
44+
import (
45+
"context"
46+
47+
"go.temporal.io/sdk/activity"
48+
)
49+
50+
func YourSimpleActivity(ctx context.Context) error {
51+
return nil
52+
}
53+
```
54+
55+
</TabItem>
56+
<TabItem value="java" label="Java">
57+
58+
**[Activity Definition in Java (Interface)](/develop/java/activities/basics)**
59+
60+
```java
61+
@ActivityInterface
62+
public interface GreetingActivities {
63+
@ActivityMethod
64+
String composeGreeting(String greeting, String language);
65+
}
66+
```
67+
68+
**[Activity Definition in Java (Implementation)](/develop/java/activities/basics)**
69+
70+
```java
71+
static class GreetingActivitiesImpl implements GreetingActivities {
72+
@Override
73+
public String composeGreeting(String greeting, String name) {
74+
return greeting + " " + name + "!";
75+
}
76+
}
77+
```
78+
79+
</TabItem>
80+
<TabItem value="php" label="PHP">
81+
82+
**[Activity Definition in PHP (Interface)](/develop/php/activities/basics)**
83+
84+
```php
85+
#[ActivityInterface]
86+
interface GreetingActivities
87+
{
88+
public function composeGreeting(string $greeting, string $name): string;
89+
}
90+
```
91+
92+
**[Activity Definition in PHP (Implementation)](/develop/php/activities/basics)**
93+
94+
```php
95+
class GreetingActivitiesImpl implements GreetingActivities
96+
{
97+
public function composeGreeting(string $greeting, string $name): string
98+
{
99+
return $greeting . ' ' . $name;
100+
}
101+
}
102+
```
103+
104+
</TabItem>
105+
<TabItem value="python" label="Python">
106+
107+
**[Activity Definition in Python](/develop/python/activities/basics)**
108+
109+
```python
110+
from temporalio import activity
111+
112+
@activity.defn(name="your_activity")
113+
async def your_activity(input: YourParams) -> str:
114+
return f"{input.greeting}, {input.name}!"
115+
```
116+
117+
</TabItem>
118+
<TabItem value="typescript" label="TypeScript">
119+
120+
**[Activity Definition in TypeScript](/develop/typescript/activities/basics)**
121+
122+
```ts
123+
export async function greet(name: string): Promise<string> {
124+
return `Hello, ${name}!`;
125+
}
126+
```
127+
128+
</TabItem>
129+
<TabItem value="dotnet" label=".NET">
130+
131+
**[Activity Definition in C# and .NET](/develop/dotnet/activities/basics)**
132+
133+
```csharp
134+
using Temporalio.Activities;
135+
136+
public class MyActivities
137+
{
138+
[Activity]
139+
public string MyActivity(MyActivityParams input) =>
140+
$"{input.Greeting}, {input.Name}!";
141+
}
142+
```
143+
144+
</TabItem>
145+
<TabItem value="rust" label="Rust">
146+
147+
**[Activity Definition in Rust](/develop/rust/activities/basics)**
148+
149+
```rust
150+
use temporalio_sdk::activities::{ActivityContext, ActivityError};
151+
use temporalio_macros::activities;
152+
153+
pub struct GreetingActivities;
154+
155+
#[activities]
156+
impl GreetingActivities {
157+
#[activity]
158+
pub async fn greet(_ctx: ActivityContext, name: String) -> Result<String, ActivityError> {
159+
Ok(format!("Hello, {}!", name))
160+
}
161+
}
162+
```
163+
164+
</TabItem>
165+
</Tabs>
166+
167+
For full SDK-specific guides, see:
168+
36169
- [How to develop an Activity Definition using the Go SDK](/develop/go/activities/basics)
37170
- [How to develop an Activity Definition using the Java SDK](/develop/java/activities/basics)
38171
- [How to develop an Activity Definition using the PHP SDK](/develop/php/activities/basics)
39172
- [How to develop an Activity Definition using the Python SDK](/develop/python/activities/basics)
40173
- [How to develop an Activity Definition using the TypeScript SDK](/develop/typescript/activities/basics)
41174
- [How to develop an Activity Definition using the .NET SDK](/develop/dotnet/activities/basics)
175+
- [How to develop an Activity Definition using the Rust SDK](/develop/rust/activities/basics)
42176

43177
The term 'Activity Definition' is used to refer to the full set of primitives in any given language SDK that provides an access point to an Activity Function Definition——the method or function that is invoked for an [Activity Task Execution](/tasks#activity-task-execution).
44178
Therefore, the terms Activity Function and Activity Method refer to the source of an instance of an execution.

docs/encyclopedia/workflow/workflow-definition.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,35 @@ public class YourBasicWorkflow {
143143
}
144144
```
145145

146+
</TabItem>
147+
<TabItem value="rust" label="Rust">
148+
149+
**[Workflow Definition in Rust](/develop/rust/workflows/basics)**
150+
151+
```rust
152+
use temporalio_macros::{workflow, workflow_methods};
153+
use temporalio_sdk::{WorkflowContext, WorkflowContextView, WorkflowResult};
154+
155+
#[workflow]
156+
pub struct YourBasicWorkflow {
157+
param: String,
158+
}
159+
160+
#[workflow_methods]
161+
impl YourBasicWorkflow {
162+
#[init]
163+
fn new(_ctx: &WorkflowContextView, param: String) -> Self {
164+
Self { param }
165+
}
166+
167+
#[run]
168+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
169+
// ...
170+
Ok(String::new())
171+
}
172+
}
173+
```
174+
146175
</TabItem>
147176

148177
</Tabs>

0 commit comments

Comments
 (0)