> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust SDK reference

> This topic documents how to get started with the server-side Rust SDK, and links to reference information on all of the supported features.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

<Note title="Recent major versions">
  **Version 3 of the Rust SDK includes breaking changes**. The most significant changes involve the HTTP transport layer, TLS/crypto feature flags, and some API refinements. To learn how to upgrade, read the [Rust SDK 2.x to 3.0 migration guide](/sdk/server-side/rust/migration-2-to-3).

  **Version 2 of the Rust SDK makes the `rustls` dependency optional**. There are no changes to the SDK API.
</Note>

## Overview

This topic documents how to get started with the server-side Rust SDK, and links to reference information on all of the supported features.

<Note title="SDK quick links">
  LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
</Note>

| Resource | Location |
| - | - |
| SDK API documentation | [SDK API docs](https://docs.rs/launchdarkly-server-sdk) |
| Supported SDK Versions | [Rust server SDK](../concepts/supported-versions#rust-server-sdk) |
| GitHub repository | [rust-server-sdk](https://github.com/launchdarkly/rust-server-sdk) |
| Sample application | [Rust](https://github.com/launchdarkly/hello-rust) |
| Published module | [crates.io](https://crates.io/crates/launchdarkly-server-sdk) |

## Get started

After you complete the [Get started process](/home/getting-started), follow these instructions to start using the LaunchDarkly SDK in your Rust application.

### Install the SDK

First, install the LaunchDarkly SDK as a dependency in your application.

<CodeGroup>
  ```bash title="Shell" theme={null}
      cargo add launchdarkly-server-sdk
  ```
</CodeGroup>

### Initialize the client

Next, import the LaunchDarkly client in your application code:

<CodeGroup>
  ```rust title="Rust" theme={null}
      use launchdarkly_server_sdk::{Client, ConfigBuilder, ContextBuilder, ServiceEndpointsBuilder};
  ```
</CodeGroup>

<Note title="The Rust SDK uses an SDK key">
  The Rust SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
</Note>

After you install and import the SDK, create a single, shared instance of the LaunchDarkly client. Specify your SDK key here so that your application is authorized to connect to LaunchDarkly, your application, and your environment.

Once you have created the client, start the client process and wait for the client to initialize. This SDK depends on the tokio crate to provide a default runtime and as such it is a required dependency.

Only create one instance of `client`.

Here's how:

<CodeGroup>
  ```rust title="Rust, v3.0+" theme={null}
      use std::time::Duration;

      #[tokio::main]
      async fn main() {
          let config = ConfigBuilder::new(&YOUR_SDK_KEY).build();
          let client = Client::build(config).unwrap();

          client.start_with_default_executor();

          let initialized = client
              .wait_for_initialization(Duration::from_secs(10))
              .await
              .unwrap_or(false);

          if !initialized {
              panic!("Client failed to successfully initialize");
          }
      }
  ```
</CodeGroup>

To learn more about the specific configuration options available in this SDK, read [`Config`](https://docs.rs/launchdarkly-server-sdk/latest/launchdarkly_server_sdk/struct.Config.html).

<Warning title="client must be a singleton">
  It's important to make `client` a singleton for each LaunchDarkly project. The client instance maintains internal state that allows LaunchDarkly to serve feature flags without making any remote requests. Do not instantiate a new client with every request.

  If you have multiple LaunchDarkly projects, you can create one `LDClient` for each. In this situation, the clients operate independently. For example, they do not share a single connection to LaunchDarkly.
</Warning>

### Evaluate a context

You can use `client` to check which variation a particular context will receive for a given feature flag.

Here's how:

<CodeGroup>
  ```rust title="Rust" theme={null}
      let context = ContextBuilder::new("example-context-key").build();
      let show_feature = client.bool_variation(&context, "example-flag-key", false);

      if show_feature {
        # application code to show the feature
      } else {
        # the code to run if the feature is off
      }
  ```
</CodeGroup>

## Shut down the client

Shut down the client when your application terminates. To learn more, read [Shutting down](/sdk/features/shutdown#rust).

## Supported features

This SDK supports the following features:

* [Anonymous contexts and users](/sdk/features/anonymous#rust)
* [Configuration](/sdk/features/config#rust), including
  * [Application metadata configuration](/sdk/features/app-config#rust)
* [Context configuration](/sdk/features/context-config/server-side#rust)
* [Evaluating flags](/sdk/features/evaluating#rust)
* [Flag evaluation reasons](/sdk/features/evaluation-reasons/server-side#rust)
* [Flushing events](/sdk/features/flush#rust)
* [Getting all flags](/sdk/features/all-flags#rust)
* [Identifying and changing contexts](/sdk/features/identify#rust)
* [Logging configuration](/sdk/features/logging#rust)
* [Migrations](/sdk/features/migrations#rust)
* [Offline mode](/sdk/features/offline-mode#rust)
* [Private attributes](/sdk/features/private-attributes/server-side#rust)
* [Relay Proxy configuration](/sdk/features/relay-proxy-configuration)
  * [Using proxy mode](/sdk/features/relay-proxy-configuration/proxy-mode#rust)
  * [Using daemon mode](/sdk/features/relay-proxy-configuration/daemon-mode#rust)
* [Secure mode](/sdk/features/secure-mode#rust)
* [Sending custom events](/sdk/features/events#rust)
* [Service endpoint configuration](/sdk/features/service-endpoint-configuration/server-side#rust)
* [Shutting down](/sdk/features/shutdown#rust)
* [Test data sources](/sdk/features/test-data-sources#rust)
* [Web proxy configuration](/sdk/features/web-proxy#rust)
