# AddRustApp

- Module: [Aspire.Hosting.Rust](/reference/api/go/aspire.hosting.rust.md)
- Version: `17.0.0-preview.1.26565.2`
- Kind: `method`
- Defined on: `DistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Adds a Rust application to the application model.

## Remarks

The resource runs `cargo run` in `appDirectory`. Cargo discovers the manifest
from that directory by default; use `WithCargoManifestPath` to select another manifest. Cargo
requires the two kinds of argument to be separated by `--`, so they are configured separately:
`WithCargoArgs` adds arguments for cargo itself (before the separator) and `WithArgs` adds
arguments for the application (after it).
Debugging is wired up automatically. In VS Code the resource is built with `cargo build` and
the resulting binary is launched under a native debugger, so the cargo arguments are applied to
the build rather than to `cargo run`.
Aspire configures the OTLP endpoint and development certificate environment variables. The Rust
application must still enable the transport and TLS features required by its OpenTelemetry SDK and
load native trust roots when using the development certificate. Rust does not read a port from the
environment on its own, so bind to the port named by `WithHttpEndpoint(env: ...)` rather than a
hard-coded one.
When publishing, a multi-stage Dockerfile is generated that builds the crate inside the container;
the crate is never compiled on the host. If the app directory already contains a `Dockerfile`,
that file is used instead. Call `WithDockerfileBaseImage` once with both arguments to override
the build and runtime base images together; each call replaces the previous image configuration.

## Definition

```go
func (DistributedApplicationBuilder) AddRustApp(
    name string,
    appDirectory string,
) RustAppResource
```

## Parameters

- `name` (`string`) -- The name of the resource.
- `appDirectory` (`string`) -- The working directory for cargo and the Docker build context used when publishing.

## Returns

[`RustAppResource`](/reference/api/go/aspire.hosting.rust/rustappresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- `DistributedApplicationBuilder`
