---
name: rust-module-validator
description: "A checklist to prove a Rust module is sound before it merges (public API as declared, Cargo.toml in order, builds on the minimum Rust version) plus a compile-and-call test file to paste into the tests folder. Use when a Rust module needs a pre-merge checklist and a compile-time test that proves its public API, dependencies, and minimum Rust version all hold. Do not use for writing the module's unit tests for behaviour, reviewing its design, or benchmarking it. Related topics: coding, rust."
---

# Rust Module Validator

A checklist to prove a Rust module is sound before it merges (public API as declared, Cargo.toml in order, builds on the minimum Rust version) plus a compile-and-call test file to paste into the tests folder.

## When to use

Use this skill when a Rust module needs a pre-merge checklist and a compile-time test that proves its public API, dependencies, and minimum Rust version all hold. Do not use it for writing the module's unit tests for behaviour, reviewing its design, or benchmarking it.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Write each check as a command with an expected result: module declared, signatures exact, edition matching, build on the minimum toolchain, clippy and doc warnings clean.
3. When the Cargo.toml check is on, add rows for rust-version, edition, and the dependency features the module needs.
4. Compare the declared dependencies to the module's imports and list anything missing or unused.
5. Write the test module so it constructs every public type and calls every public function with trivial arguments, so a signature change breaks compilation.
6. Read the checklist once more and remove any item that cannot be verified by running something.

## Inputs

- **Module name** (free text, e.g. "my_module")
- **File path** (free text, e.g. "src/my_module.rs")
- **Public items to verify** (longer free text)
- **Rust edition** (choose one: 2015, 2018, 2021, 2024)
- **Include Cargo.toml check** (choose one: Yes, No)
- **Minimum Rust version** (free text, e.g. "1.70")
- **Input 7** (choose one: cfg(test))

## Output

A Validation Checklist section with one bullet per check (command and expected result), then a rust code block labeled test with a #[cfg(test)] module that exercises every public item.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Rust Module Validation Plan

Build a validation plan for this Rust module.

- Module name: {{Module name}}
- File path: {{File path}}
- Public items to verify: {{Public items to verify}}
- Rust edition: {{Rust edition}}
- Include Cargo.toml check: {{Include Cargo.toml check}}
- Minimum Rust version: {{Minimum Rust version}}

Write the checklist as concrete commands and observable results, not reminders. Cover: the module is declared in its parent with mod and the intended visibility; every listed public item exists with that exact signature; the edition in Cargo.toml matches; the crate builds on the minimum toolchain with cargo +<version> build and uses no feature newer than that toolchain; cargo clippy at the default level and cargo doc with warnings denied both pass; every dependency the module imports is declared, and nothing declared is unused. When the Cargo.toml check is on, add rows for rust-version, edition, and the dependency features the module needs. Then write the test file: an integration test that imports the crate, calls each public function with a trivial argument, and constructs each public type, so a changed signature fails to compile rather than failing at runtime.

Return a markdown section titled Validation Checklist with one bullet per check (command and expected result), then a rust code block labeled test containing a #{{Input 7}} module with one test that constructs every public type and calls every public function.

## Pitfalls

- Writing checklist items like 'ensure the API is correct' that nobody can run, so the checklist gets skipped.
- Testing only that the crate compiles, which passes even when a public function was deleted.
- Setting rust-version in Cargo.toml without actually building on that toolchain, so the claim is never verified.
