Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@
[submodule "translations/docs-zh"]
path = translations/docs-zh
url = https://github.com/dapr/docs-zh.git
branch = v1.0_content
[submodule "sdkdocs/rust"]
path = sdkdocs/rust
url = https://github.com/dapr/rust-sdk.git
branch = v1.0_content
4 changes: 2 additions & 2 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ module:
- source: sdkdocs/js/content/en/js-sdk-contributing
target: content/contributing/sdk-contrib/
lang: en
- source: sdkdocs/rust/daprdocs/content/en/rust-sdk-docs
- source: sdkdocs/rust/content/en/rust-sdk-docs
target: content/developing-applications/sdks/rust
lang: en
- source: sdkdocs/rust/daprdocs/content/en/rust-sdk-contributing
- source: sdkdocs/rust/content/en/rust-sdk-contributing
target: content/contributing/sdk-contrib/
lang: en
- source: sdkdocs/pluggable-components/dotnet/content/en/dotnet-sdk-docs
Expand Down
1 change: 0 additions & 1 deletion sdkdocs/rust
Submodule rust deleted from 4475ed
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
type: docs
title: "Contributing to the Rust SDK"
linkTitle: "Rust SDK"
weight: 3000
description: Guidelines for contributing to the Dapr Rust SDK
---

When contributing to the [Rust SDK](https://github.com/dapr/rust-sdk) the following rules and best-practices should be followed.

## Examples

The `examples` directory contains code samples for users to run to try out specific functionality of the various Rust SDK packages and extensions. It also hosts component examples used for validation. When writing new and updated samples keep in mind:

- All examples should be runnable on Windows, Linux, and MacOS. While Rust code is consistent among operating systems aside from minor OS-feature gating, any pre/post example commands should provide options through [tabpane]({{% ref "contributing-docs.md#tabbed-content" %}})
- Contain steps to download/install any required pre-requisites. Someone coming in with a fresh OS install should be able to start on the example and complete it without an error. Links to external download pages are fine.
- Examples should be pass validation and include mechanical markdown steps and be added to the validation workflow [TBA](#)

## Docs

The `daprdocs` directory contains the markdown files that are rendered into the [Dapr Docs](https://docs.dapr.io) website. When the documentation website is built this repo is cloned and configured so that its contents are rendered with the docs content. When writing docs keep in mind:

- All rules in the [docs guide]({{% ref contributing-docs.md %}}) should be followed in addition to these.
- All files and directories should be prefixed with `rust-` to ensure all file/directory names are globally unique across all Dapr documentation.

## Update Protobufs

To pull the protobufs from the `dapr/dapr` repo you can run the script in the repo root like so:

```bash
./update-protos.sh
```

By default, the script fetches the latest proto updates from the master branch of the Dapr repository. If you need to choose a specific release or version, use the -v flag:

```bash
./update-protos.sh -v v1.13.0
```
27 changes: 27 additions & 0 deletions sdkdocs/rust/content/en/rust-sdk-docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
type: docs
title: "Dapr Rust SDK"
linkTitle: "Rust"
weight: 1000
description: Rust SDK packages for developing Dapr applications
no_list: true
cascade:
github_repo: https://github.com/dapr/rust-sdk
github_subdir: daprdocs/content/en/rust-sdk-docs
path_base_for_github_subdir: content/en/developing-applications/sdks/rust/
github_branch: main
---

{{% alert title="Note" color="primary" %}}
The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a stable release and will likely involve breaking changes.
{{% /alert %}}

A client library to help build Dapr applications using Rust. This client is targeting support for all public Dapr APIs while focusing on idiomatic Rust experiences and developer productivity.

{{% cardpane %}}
{{% card title="**Client**" %}}
Use the Rust Client SDK for invoking public Dapr APIs

[Learn more about the Rust Client SDK]({{% ref rust-client %}})
{{% /card %}}
{{% /cardpane %}}
127 changes: 127 additions & 0 deletions sdkdocs/rust/content/en/rust-sdk-docs/rust-client/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
type: docs
title: "Getting started with the Dapr client Rust SDK"
linkTitle: "Client"
weight: 20000
description: How to get up and running with the Dapr Rust SDK
no_list: true
---

The Dapr client package allows you to interact with other Dapr applications from
a Rust application.

{{% alert title="Note" color="primary" %}}
The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a
stable release and will likely involve breaking changes.
{{% /alert %}}

## Prerequisites

- [Dapr CLI]({{% ref install-dapr-cli.md %}}) installed
- Initialized [Dapr environment]({{% ref install-dapr-selfhost.md %}})
- [Rust installed](https://www.rust-lang.org/tools/install)

## Import the client package

Add Dapr to your `cargo.toml`

```toml
[dependencies]
dapr = "0.16"
```

You can either reference `dapr::Client` or bind the full path to a new name as follows:

```rust
use dapr::Client as DaprClient;
```

## Instantiating the Dapr client

```rust
let addr = "https://127.0.0.1".to_string();

let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr,
port).await?;
```

Alternatively if you would like to specify a custom port, this can be done by using this connect method:

```rust
let mut client = dapr::Client::<dapr::client::TonicClient>::connect_with_port(addr, "3500".to_string()).await?;
```

## Building blocks

The Rust SDK allows you to interface with the
[Dapr building blocks]({{% ref building-blocks %}}).

### Service Invocation (gRPC)

To invoke a specific method on another service running with Dapr sidecar, the
Dapr client provides two options:

Invoke a (gRPC) service

```rust
let response = client
.invoke_service("service-to-invoke", "method-to-invoke", Some(data))
.await
.unwrap();
```

For a full guide on service invocation, visit
[How-To: Invoke a service]({{% ref howto-invoke-discover-services.md %}}).

### State Management

The Dapr Client provides access to these state management methods: `save_state`
, `get_state`, `delete_state` that can be used like so:

```rust
let store_name = String::from("statestore");

let key = String::from("hello");
let val = String::from("world").into_bytes();

// save key-value pair in the state store
client
.save_state(store_name, key, val, None, None, None)
.await?;

let get_response = client
.get_state("statestore", "hello", None)
.await?;

// delete a value from the state store
client
.delete_state("statestore", "hello", None)
.await?;
```

Multiple states can be sent with the `save_bulk_states` method.

For a full guide on state management, visit
[How-To: Save & get state]({{% ref howto-get-save-state.md %}}).

### Publish Messages

To publish data onto a topic, the Dapr client provides a simple method:

```rust
let pubsub_name = "pubsub-name".to_string();
let pubsub_topic = "topic-name".to_string();
let pubsub_content_type = "text/plain".to_string();

let data = "content".to_string().into_bytes();
client
.publish_event(pubsub_name, pubsub_topic, pubsub_content_type, data, None)
.await?;
```

For a full guide on pub/sub, visit
[How-To: Publish & subscribe]({{% ref howto-publish-subscribe.md %}}).

## Related links

[Rust SDK Examples](https://github.com/dapr/rust-sdk/tree/master/examples)
Loading