On this page

Rust

Guara Cloud fully supports Rust applications, including frameworks like Actix Web, Axum, Rocket, and any other Rust-based project. Rust’s compiled nature produces small, fast binaries that are ideal for containerized deployments.

Supported versions

The following Rust versions are auto-detected by Buildpack:

  • Rust 1.80
  • Rust 1.81
  • Rust 1.82

The version is determined from the rust-version field in your Cargo.toml or from a rust-toolchain.toml file. If no version is specified, the latest stable version is used.

# Cargo.toml
[package]
name = "my-app"
version = "0.1.0"
edition = "2021"
rust-version = "1.82"

Deploy with Dockerfile

A multi-stage build is the recommended approach for Rust applications. It compiles your binary in a full Rust environment, then copies only the binary into a minimal runtime image.

FROM rust:1.82 AS builder

WORKDIR /app

COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -rf src

COPY . .
RUN touch src/main.rs
RUN cargo build --release

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY --from=builder /app/target/release/my-app .

EXPOSE 3000

CMD ["./my-app"]

Deploy with Buildpack

If your repository does not contain a Dockerfile, Guara Cloud automatically detects your Rust project by the presence of a Cargo.toml file in the root directory.

The Buildpack will:

  1. Detect the Rust version from Cargo.toml or rust-toolchain.toml
  2. Download dependencies and cache them for faster rebuilds
  3. Build your application in release mode with cargo build --release
  4. Start the compiled binary

Cargo workspaces are also supported. The Buildpack detects the workspace structure and builds the appropriate binary.

Port configuration

Your application must listen on the port configured in your service settings. The default is 3000, but you can change it at any time to match your application.

use std::env;

let port = env::var("PORT").unwrap_or_else(|_| "3000".to_string());
let addr = format!("0.0.0.0:{}", port);

Example project structure

my-rust-app/
  Cargo.toml
  Cargo.lock
  src/
    main.rs
    routes/
    models/
  Dockerfile          # optional — omit to use Buildpack

Environment variables

These environment variables are commonly used with Rust deployments:

VariableRecommended valueDescription
PORTSet by platformThe port your application must listen on
RUST_LOGinfoControls log verbosity for the tracing/env_logger crate
RUST_BACKTRACE1Enables backtraces on panic for easier debugging

Common pitfalls