AgentSkillsCN

rust-dev

适用于在 crates/ 目录下编写或修改 Rust 代码时使用。包含编码规范、测试文件命名规则、数学文档撰写准则,以及测试哲学。

SKILL.md
--- frontmatter
name: rust-dev
description: Use when writing or modifying Rust code in crates/. Contains coding conventions, test file naming, mathematical documentation rules, and testing philosophy.

Rust crate conventions

Coding conventions

  • Colocated tests: foo.rs has foo_test.rs in the same directory. Submodule tests use #[path = "foo_test.rs"].
  • A source file may have multiple test files (e.g. foo_math_test.rs, foo_test.rs)
  • Functional programming style
  • Types encode mathematical invariants, validated at construction
  • nalgebra for linear algebra, proptest for property-based testing

Mathematical documentation

  • Definitions, lemmas, and proofs live as doc comments on the corresponding types/functions
  • Long proofs are outsourced to colocated *_proof.md files
  • The Rust crates are self-contained mathematically — no dependency on thesis/. The thesis is downstream
  • Quality bar: specific, correct, detailed, clearly written enough that (1) Jörn can verify with low effort and (2) agents can rely on them when implementing

Testing philosophy

Two classes of tests, both applied excessively:

  1. Math proposition tests (due diligence falsification): proptest generators approximate mathematical quantifiers ("∀ polytopes K", "∀ A ∈ Sp(4)", etc.). Properties under test are mathematical propositions (e.g. J^2 = -I, symplectomorphisms preserve capacity).
  2. Standard correctness tests: Rust best practices for correctness-critical code — edge cases, invariant checking, regression tests.