跳转到内容
DocsTry Aspire
DocsTry

Get started with the Rust integration

此内容尚不支持你的语言。

Rust logo ⭐ Community Toolkit

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.

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
  • Install Rust with rustup and make cargo available on your PATH.
  • Install Bacon when you use AddBaconApp / addBaconApp.
  • Create an Aspire AppHost in C# or TypeScript.
  1. Add CommunityToolkit.Aspire.Hosting.Rust to your AppHost. You can use aspire add communitytoolkit-rust or install the NuGet package directly.

  2. 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();
  3. 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