Get started with the Rust integration

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

Rust logo

Rust is a systems programming language that guarantees memory safety without a garbage collector, which makes it a popular choice for fast, reliable web services, workers, and command-line tools. Rust projects are built and run with Cargo, Rust’s build tool and package manager. The Aspire Rust hosting integration lets you model Cargo apps as first-class resources in your AppHost and connect them to the rest of your app, regardless of the language each part is written in.

Adding Rust apps through Aspire — rather than starting each cargo run by hand and wiring up ports, URLs, and credentials yourself — gives you:

  • Cargo-native configuration. Aspire runs each app with cargo run in its own directory, so Cargo finds the app’s manifest, workspace, and lockfile as it does in a terminal. Select features, binaries, examples, workspace members, profiles, and target triples with AppHost methods, and pass your program’s own arguments separately.
  • Service discovery and connection information. Reference a Rust app from another resource — or reference databases, caches, and other services from a Rust app — and Aspire injects URLs and connection details as environment variables that your app reads with std::env::var.
  • Telemetry in the dashboard. Every Rust resource receives the standard OpenTelemetry exporter settings, so an app that exports telemetry with the OpenTelemetry SDK for Rust shows its traces, metrics, and logs in the dashboard. Cargo’s build output and your app’s console output appear in the dashboard’s console logs.
  • Trusted development certificates. Aspire points OpenSSL and the rustls-native-certs crate at a directory that contains the development certificate, so HTTPS calls between local resources work without turning off certificate validation.
  • Debugging. Debug Rust apps in VS Code with the standard Aspire debugging flow. Aspire builds each app with the same Cargo options that cargo run uses, and launches the binary under a native debugger.
  • Publishing without a hand-written Dockerfile. When you publish, Aspire builds each Rust app into a container image with the Dockerfile in the app directory or, when there isn’t one, with a multi-stage Dockerfile that it generates. By default, the generated Dockerfile makes a release build — locked to the dependency versions in Cargo.lock, when the app has that file — and runs the app as an unprivileged user.
  • The Rust toolchain, with Cargo 1.71 or later on your PATH, for each Rust app that the AppHost runs locally. Install it with rustup. When Aspire generates the Dockerfile to publish an app, it builds the app inside the container image, but it still runs cargo metadata on your machine to find the app’s binary.
  • To debug in VS Code, the C/C++ extension on Windows, or the CodeLLDB extension on Linux and macOS.
  • The Aspire CLI, along with the other Aspire prerequisites.

The Rust integration is a hosting integration. You install it in your AppHost and add a resource for each Rust app. When a Rust app starts, Aspire runs it with Cargo, supplies its configuration as environment variables, and shows its logs, status, and telemetry in the dashboard.

architecture-beta

  group apphost(server)[AppHost]
  group rustapp(server)[Rust app]

  service hosting(server)[Rust hosting integration] in apphost
  service resource(logos:rust)[Rust app resource] in apphost
  service toolchain(logos:rust)[Cargo] in rustapp
  service app(logos:rust)[Rust process] in rustapp

  hosting:R --> L:resource
  resource:R --> L:toolchain
  toolchain:R --> L:app

There’s no Aspire client crate for Rust. Your app reads the environment variables that Aspire injects with std::env::var, or with the configuration crate of your choice, and exports telemetry with the OpenTelemetry SDK for Rust.

Getting there is a two-step process: model your Rust apps in the AppHost, then connect them to — and from — the other resources in your app.

  1. Add the Rust hosting integration to your AppHost, then declare a resource for each Rust app. The Set up Rust apps in the AppHost article walks through every capability — endpoints and health checks, Cargo features, binaries, workspace members, profiles, and target triples, program arguments, certificate trust, debugging, and publishing — with side-by-side TypeScript and C# examples.

    Set up Rust apps in the AppHost

  2. When you reference a Rust app from another resource, Aspire injects the app’s URLs into that resource. When you reference other resources from a Rust app, Aspire injects their connection information into the app’s environment. See Connect to Rust apps for the environment variable reference, examples in C#, Go, Python, and TypeScript, and how Rust apps read Aspire configuration and send telemetry to the dashboard.

    Connect to Rust apps