Skip to content

Commit

Permalink
Merge pull request #245 from mikeee/dapr-docs
Browse files Browse the repository at this point in the history
Update Dapr Rust docs
  • Loading branch information
mikeee authored Nov 25, 2024
2 parents 709c67e + e78cab4 commit 4cfa9a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion daprdocs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All Dapr documentation is hosted at [docs.dapr.io](https://docs.dapr.io), includ

### Rust SDK docs source

Although the docs site code and content is in the [docs repo](https://github.com/dapr/docs), the Go SDK content and images are within the `content` and `static` directories, respectively.
Although the docs site code and content is in the [docs repo](https://github.com/dapr/docs), the Rust SDK content and images are within the `content` and `static` directories, respectively.

This allows separation of roles and expertise between maintainers, and makes it easy to find the docs files you are looking for.

Expand Down
37 changes: 22 additions & 15 deletions daprdocs/content/en/rust-sdk-docs/rust-client/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ 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.
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.
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
Expand All @@ -19,55 +21,57 @@ The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a stabl
- 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]
# Other dependencies
dapr = "0.13.0"
dapr = "0.16.0"
```

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
const addr: String = "https://127.0.0.1";
const port: String = "50001";
let addr = "https://127.0.0.1".to_string();

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


## Building blocks

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

### Service Invocation

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

Invoke a 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 >}}).
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:
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");
Expand All @@ -92,10 +96,11 @@ client

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 >}}).
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 Go client provides a simple method:

```rust
Expand All @@ -109,7 +114,9 @@ client
.await?;
```

For a full guide on pub/sub, visit [How-To: Publish & subscribe]({{< ref howto-publish-subscribe.md >}}).
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)

0 comments on commit 4cfa9a3

Please sign in to comment.