Skip to content

Rust

Rust is a systems programming language focused on safety, concurrency, and performance. LumenFlow’s rust preset integrates with Cargo for comprehensive quality gates.

  1. Add preset to your configuration

    # .lumenflow.config.yaml
    version: '2.0'
    
    gates:
      execution:
        preset: 'rust'
  2. Run gates

    pnpm gates
    # Or with the GitHub Action
  3. Done!

    The preset runs cargo fmt, cargo clippy, cargo check, and cargo test automatically.

The rust preset uses these commands:

GateCommandDescription
Formatcargo fmt --checkCheck code formatting
Lintcargo clippyCatch common mistakes and improve code
Typecheckcargo checkFast type checking without full build
Testcargo testRun all tests

Override specific commands while keeping preset defaults for others:

gates:
  execution:
    preset: 'rust'
    # Fail on any clippy warnings
    lint: 'cargo clippy -- -D warnings'
    # Run tests with output
    test: 'cargo test -- --nocapture'

For complete control, omit the preset and define all commands:

gates:
  execution:
    format: 'cargo fmt --all --check'
    lint: 'cargo clippy --all-targets --all-features -- -D warnings'
    typecheck: 'cargo check --all-targets --all-features'
    test: 'cargo test --all-features'

Treat all Clippy warnings as errors:

gates:
  execution:
    preset: 'rust'
    lint: 'cargo clippy --all-targets --all-features -- -D warnings'

Configure additional lints in Cargo.toml:

[lints.rust]
unsafe_code = "forbid"

[lints.clippy]
all = "deny"
pedantic = "warn"

Add test coverage using cargo-tarpaulin:

gates:
  execution:
    preset: 'rust'
    test: 'cargo tarpaulin --out Xml'

Or using cargo-llvm-cov:

gates:
  execution:
    preset: 'rust'
    test: 'cargo llvm-cov --lcov --output-path lcov.info'

Ensure all features and targets compile:

gates:
  execution:
    preset: 'rust'
    typecheck: 'cargo check --all-targets --all-features'
    lint: 'cargo clippy --all-targets --all-features -- -D warnings'
    test: 'cargo test --all-features'

Include documentation build in gates:

gates:
  execution:
    preset: 'rust'
    # Add doc build to typecheck
    typecheck: 'cargo check && cargo doc --no-deps'
name: LumenFlow Gates

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  gates:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Run LumenFlow Gates
        uses: hellmai/lumenflow-gates@v1
        with:
          token: ${{ secrets.LUMENFLOW_TOKEN }}

LumenFlow works well with standard Cargo project layouts:

myproject/
├── .lumenflow.config.yaml
├── Cargo.toml
├── Cargo.lock
├── src/
│   ├── lib.rs
│   └── main.rs
├── tests/
│   └── integration_test.rs
└── benches/
    └── benchmark.rs

For Cargo workspaces, LumenFlow runs gates across all crates:

gates:
  execution:
    preset: 'rust'
    # Workspace-wide commands
    format: 'cargo fmt --all --check'
    lint: 'cargo clippy --workspace --all-targets -- -D warnings'
    typecheck: 'cargo check --workspace --all-targets'
    test: 'cargo test --workspace'

Example workspace structure:

myworkspace/
├── .lumenflow.config.yaml
├── Cargo.toml              # [workspace] definition
├── crates/
│   ├── core/
│   │   ├── Cargo.toml
│   │   └── src/lib.rs
│   ├── api/
│   │   ├── Cargo.toml
│   │   └── src/lib.rs
│   └── cli/
│       ├── Cargo.toml
│       └── src/main.rs

If using nightly-only features:

gates:
  execution:
    preset: 'rust'
    format: 'cargo +nightly fmt --check'
    lint: 'cargo +nightly clippy -- -D warnings'

In CI, install the nightly toolchain:

- uses: dtolnay/rust-toolchain@nightly
  with:
    components: rustfmt, clippy

Filter to your code only:

lint: 'cargo clippy --all-targets -- -D warnings -A clippy::cargo'

Use caching and consider splitting jobs:

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --all-targets

  test:
    runs-on: ubuntu-latest
    needs: check
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test

Test specific feature combinations:

gates:
  execution:
    preset: 'rust'
    test: |
      cargo test --no-default-features
      cargo test --all-features
      cargo test --features "feature1,feature2"

For cross-compilation targets, add the target in CI:

- uses: dtolnay/rust-toolchain@stable
  with:
    targets: wasm32-unknown-unknown

- name: Check WASM build
  run: cargo check --target wasm32-unknown-unknown