Hamburger Cross Icon
Rust Collector - Lunar Collector

Rust Collector

Collector Beta LanguagesBuild

Analyze Rust projects to collect crate metadata, dependencies, unsafe block usage, test coverage, and clippy lint results. Supports Cargo workspaces.

Add rust to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/rust@v1.0.0

What This Integration Collects

This integration includes 5 collectors that gather metadata from your systems.

Collector code

project

Analyzes Rust project structure by detecting Cargo.toml, Cargo.lock, rust-toolchain.toml, clippy and rustfmt configuration, workspace members, edition, MSRV, and crate type (library vs binary). Counts unsafe blocks and records their locations. Writes project metadata to .lang.rust.

rust cargo Cargo.toml project structure unsafe edition workspace
Book a demo
Collector code

dependencies

Extracts direct, dev, and build dependencies from Cargo.toml. When Cargo.lock is present, also extracts resolved transitive dependency versions. Writes dependency data to .lang.rust.dependencies.

rust dependencies cargo dependencies crates supply chain
Book a demo
Collector code

clippy

Runs cargo clippy with JSON output and collects structured lint warnings. Parses each diagnostic into file, line, message, and lint name. Writes pass/fail status and normalized warnings to .lang.rust.lint.

clippy rust linting static analysis code quality
Book a demo
Collector ci-before-command

cicd

Records every cargo command executed in CI pipelines along with the Rust toolchain version. Writes command strings and version info to .lang.rust.cicd for audit trails and build reproducibility analysis.

rust ci cargo version ci commands build tracking
Book a demo
Collector ci-after-command

test-coverage

Extracts coverage percentage from cargo-tarpaulin or cargo-llvm-cov output after tests complete. Parses coverage reports and writes results to .lang.rust.tests.coverage.

code coverage tarpaulin llvm-cov test coverage coverage metrics
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "lang": {
    "rust": {
      "edition": "2021",
      "version": "1.75.0",
      "msrv": "1.70.0",
      "build_systems": ["cargo"],
      "cargo_toml_exists": true,
      "cargo_lock_exists": true,
      "rust_toolchain_exists": true,
      "clippy_configured": true,
      "rustfmt_configured": true,
      "is_application": true,
      "is_library": false,
      "workspace": null,
      "unsafe_blocks": {
        "count": 2,
        "locations": [
          {"file": "src/ffi.rs", "line": 42},
          {"file": "src/ffi.rs", "line": 87}
        ]
      },
      "source": { "tool": "cargo", "integration": "code" },
      "cicd": {
        "cmds": [
          { "cmd": "cargo test --all-features", "version": "1.77.0" },
          { "cmd": "cargo build --release", "version": "1.77.0" }
        ],
        "source": { "tool": "cargo", "integration": "ci" }
      },
      "tests": {
        "coverage": {
          "percentage": 74.3,
          "source": { "tool": "cargo-tarpaulin", "integration": "ci" }
        }
      },
      "dependencies": {
        "direct": [
          { "path": "serde", "version": "1.0.197", "features": ["derive"] },
          { "path": "tokio", "version": "1.36.0", "features": ["full"] }
        ],
        "dev": [
          { "path": "criterion", "version": "0.5.1" }
        ],
        "build": [
          { "path": "prost-build", "version": "0.12.3" }
        ],
        "transitive": [
          { "path": "serde_derive", "version": "1.0.197" },
          { "path": "proc-macro2", "version": "1.0.78" }
        ],
        "source": { "tool": "cargo", "integration": "code" }
      },
      "lint": {
        "passed": true,
        "warnings": [
          { "file": "src/main.rs", "line": 15, "column": 5, "message": "unused variable: `x`", "lint": "unused_variables" }
        ],
        "linters": ["clippy"],
        "source": { "tool": "clippy", "integration": "code" }
      }
    }
  }
}

Configuration

Configure this collector in your lunar-config.yml.

Inputs

Input Required Default Description
clippy_args Required Additional arguments to pass to cargo clippy (e.g., "-- -W clippy::pedantic")

Documentation

View on GitHub

Rust Collector

Collects Rust project information, CI/CD commands, test coverage, dependencies, unsafe block usage, and clippy results.

Overview

This collector gathers metadata about Rust projects including crate information, dependency graphs, unsafe block tracking, test coverage metrics, and clippy lint results. It runs on both code changes (for static analysis) and CI hooks (to capture runtime metrics like test coverage).

Note: The CI-hook collectors (test-coverage, cicd) don't run tests—they observe and collect data from cargo test / cargo tarpaulin commands that your CI pipeline already runs.

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.lang.rust object Rust project metadata (edition, MSRV, build systems)
.lang.rust.build_systems array Build systems detected (e.g., ["cargo"])
.lang.rust.cargo_toml_exists boolean Cargo.toml detected
.lang.rust.cargo_lock_exists boolean Cargo.lock detected
.lang.rust.rust_toolchain_exists boolean rust-toolchain.toml detected
.lang.rust.clippy_configured boolean Clippy config file detected
.lang.rust.rustfmt_configured boolean Rustfmt config file detected
.lang.rust.edition string Rust edition ("2021", "2024")
.lang.rust.version string Rust toolchain version
.lang.rust.msrv string Minimum Supported Rust Version from Cargo.toml
.lang.rust.is_application boolean Crate has binary targets
.lang.rust.is_library boolean Crate has a library target
.lang.rust.workspace object/null Workspace info (is_workspace, members[]) or null
.lang.rust.unsafe_blocks object Unsafe block count and locations
.lang.rust.cicd object CI/CD command tracking with Rust version
.lang.rust.tests object Test coverage information
.lang.rust.dependencies object Direct, dev, build, and transitive dependencies
.lang.rust.lint object Clippy lint results (passed, warnings)
.lang.rust.lint.passed boolean Whether clippy passed with no warnings

Note: This collector writes Rust-native coverage data to .lang.rust.tests.coverage. For normalized cross-language coverage at .testing.coverage, use a dedicated coverage tool collector (CodeCov, Coveralls, etc.).

Collectors

This plugin provides the following collectors (use include to select a subset):

Collector Hook Type Description
project code Collects project structure, edition, MSRV, unsafe blocks, workspace info
dependencies code Collects dependency graph from Cargo.toml and Cargo.lock
clippy code Runs cargo clippy and collects lint warnings
cicd ci-before-command Tracks cargo commands run in CI with version info
test-coverage ci-after-command Extracts coverage from cargo-tarpaulin or cargo-llvm-cov

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/rust@main
    on: [rust]  # Or use domain: ["domain:your-domain"]
    # include: [project, dependencies]  # Only include specific subcollectors
    # with:
    #   clippy_args: "-- -W clippy::pedantic"

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Ready to Automate Your Standards?

See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Automate Now
Turn any process doc into guardrails
Book a Demo