rust

rust gives a coding agent house rules for writing, testing and reviewing Rust. It loads whenever the agent touches Rust code, a crate's Cargo.toml, its lints or its tests, small edits included.

Why use it with an agent

An agent gets Rust to compile and pass clippy quickly. The skill covers what the compiler can't check, such as whether a failure should be a Result or a panic, and whether generated output comes out in the same order on every run.

Most of the rules are about tests. Before the agent says a test covers something, it breaks the code under test, watches the test fail and puts the code back. It counts the tests that ran, so a database suite that quietly skipped never reads as a pass. When two paths have to agree, such as a fast check and the rule it stands in for, it compares their answers across a whole grid of inputs.

The agent also leans on the type system for rules a reviewer would otherwise have to remember. Flags and sentinel values become enums, and privileged access becomes a value that only the code making the decision can create. When it ports code from Go, byte-for-byte compatibility lives in one module, and the skill lists the usual traps, such as Go's unstable sort and its JSON escaping.

Unsafe code is refused by the compiler. Rust's guarantees are the reason to use it, and unsafe switches them off. An agent stuck on a borrow error can reach for it, and a port that keeps the old language's pointers and allocators needs it everywhere just to compile. So every crate forbids it, and when a port hits that wall the agent changes the code's shape: it matches the original's behaviour, checked by diffing outputs, and lets the structure become Rust's. The unsafe a project truly needs, such as calls into a C library, lives in one small crate where each use says why it is sound.

Before it reports a change as done, it runs the formatter, clippy with warnings as errors and the whole test suite after its last edit, and says what each one printed.

Built on Microsoft's guidelines

The house rules sit on top of Microsoft's Pragmatic Rust Guidelines. The skill links each guideline by its ID, pinned to the commit the rules were checked against, and the agent opens only the guidelines for the area it is working in. In a review, it cites the rule or guideline behind each finding and ranks findings by consequence.

Where it came from

The rules come from porting a compiler and its runtime from Go to Rust with coding agents, with every output checked byte for byte against the original, and from planning Rust ports of large enterprise software projects.

The port has since shipped. Checking it against the original turned up two bugs, carried over from the Go code, that let a policy admit more callers than it read. Mutation testing found an untested branch and two guards that did nothing, and counting what ran caught a live database suite that had skipped on every CI run while the job passed.