Get started with the Rust integration
Este conteúdo não está disponível em sua língua ainda.
The Community Toolkit Rust hosting integration runs Rust applications through Cargo or Bacon alongside the other resources in your Aspire AppHost. Rust app resources support endpoints, service discovery, health checks, environment configuration, and OpenTelemetry export. They are also configured for Dockerfile publishing.
How the pieces fit together
Section titled “How the pieces fit together”The integration is installed in the AppHost. The AppHost starts Cargo or Bacon in the Rust application’s working directory, applies standard Aspire resource configuration, and exposes the resulting resource 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 or Bacon] in rustapp service app(logos:rust)[Rust process] in rustapp hosting:R --> L:resource resource:R --> L:toolchain toolchain:R --> L:app
Prerequisites
Section titled “Prerequisites”- Install Rust with rustup and make
cargoavailable on yourPATH. - Install Bacon when you use
AddBaconApp/addBaconApp. - Create an Aspire AppHost in C# or TypeScript.
-
Install the hosting package
Section titled “Install the hosting package”Add
CommunityToolkit.Aspire.Hosting.Rustto your AppHost. You can useaspire add communitytoolkit-rustor install the NuGet package directly. -
Add a Rust app
Section titled “Add a Rust app”Register the directory that contains your Rust project, then configure an endpoint for the port that the app reads from
PORT.AppHost.cs var builder = DistributedApplication.CreateBuilder(args);builder.AddRustApp("rust-api", "../rust-api").WithHttpEndpoint(port: 8080, env: "PORT").WithExternalHttpEndpoints();builder.Build().Run();apphost.mts import { createBuilder } from './.aspire/modules/aspire.mjs';const builder = await createBuilder();const api = await builder.addRustApp('rust-api', '../rust-api');await api.withHttpEndpoint({ port: 8080, env: 'PORT' });await api.withExternalHttpEndpoints();await builder.build().run(); -
Configure the app resource
Section titled “Configure the app resource”Choose Cargo or Bacon, pass command arguments, add health checks, and learn about publishing in the Rust AppHost reference.
Configure Rust apps in the AppHost