1---2name: lgtm-hq-ai-skills-stand-rust3description: Rust Standards4---56# Rust Standards78Standards for Rust code.910## Edition1112- Use the latest stable edition (2021+)13- Set `edition` explicitly in `Cargo.toml`1415## Toolchain1617- Use `/lint` for formatting and linting — lintro runs `rustfmt`, `clippy`,18 `cargo_audit`, and `cargo_deny` as configured19- Treat clippy warnings as errors in CI (`-D warnings`)20- Customize formatting via `rustfmt.toml` where needed2122## Error Handling2324- Use `thiserror` for library error types — derive structured, typed errors25- Use `anyhow` for application-level error propagation26- No `.unwrap()` in library code — use `?` or return `Result`27- `.expect()` only with descriptive messages explaining the invariant:2829 ```rust30 // Good31 let config = load_config().expect("config.toml must exist at startup");3233 // Bad34 let config = load_config().unwrap();35 ```3637- Implement `std::fmt::Display` for all custom error types3839## Type Patterns4041- Prefer newtypes for domain concepts — `struct UserId(u64)` over bare `u64`42- Use `impl Trait` in argument position for flexibility; explicit generics in return43 position for clarity44- Derive `Debug` on all public types45- Derive `Clone`, `PartialEq`, `Eq`, `Hash` where semantically appropriate46- Prefer `&str` over `String` in function arguments; return `String` when ownership47 transfers4849## Unsafe5051- `unsafe` blocks MUST include a `// SAFETY:` comment justifying soundness:5253 ```rust54 // SAFETY: pointer is guaranteed non-null by the allocator contract,55 // and the lifetime is bounded by the enclosing scope.56 unsafe { ptr.as_ref() }57 ```5859- Minimize unsafe surface area — encapsulate in safe abstractions60- Prefer safe alternatives (e.g., `std::sync::Mutex` over raw atomics) unless61 performance demands otherwise6263## Documentation6465- `///` doc comments on all public items (functions, types, traits, modules)66- Include code examples in doc comments for non-trivial APIs:6768 ```rust69 /// Parse a duration string like "5s", "100ms", or "2m".70 ///71 /// # Examples72 ///73 /// ```74 /// use mycrate::parse_duration;75 ///76 /// let d = parse_duration("5s").unwrap();77 /// assert_eq!(d, std::time::Duration::from_secs(5));78 /// ```79 pub fn parse_duration(s: &str) -> Result<Duration> { ... }80 ```8182- Use `#![deny(missing_docs)]` for library crates83- Module-level `//!` doc comments for crate and module overviews8485## Testing8687- Unit tests in `#[cfg(test)] mod tests` within the same file88- Integration tests in `tests/` directory89- Use `#[should_panic(expected = "...")]` for expected panics90- Consider `proptest` or `quickcheck` for property-based testing where valuable91- Use `assert_eq!` and `assert_ne!` over bare `assert!` for better error messages9293```rust94#[cfg(test)]95mod tests {96 use super::*;9798 #[test]99 fn parse_duration_seconds() {100 let d = parse_duration("5s").unwrap();101 assert_eq!(d, Duration::from_secs(5));102 }103104 #[test]105 #[should_panic(expected = "invalid format")]106 fn parse_duration_rejects_garbage() {107 parse_duration("not_a_duration").unwrap();108 }109}110```111112## Dependencies113114- Keep the dependency tree minimal — every dependency is an audit and supply chain115 surface116- Run vulnerability scanning via lintro (`uv run lintro chk` includes `cargo_audit`117 and `cargo_deny`)118- Pin versions in workspace `Cargo.toml` for multi-crate workspaces119- Prefer well-maintained crates with active maintainers and good documentation120121## Patterns122123- Prefer `impl` blocks over free functions for associated behavior124- Use the builder pattern for types with many optional fields125- Prefer iterators and combinators over manual loops where readability permits126- Use `#[must_use]` on functions whose return value should not be ignored127- Prefer `From`/`Into` implementations over ad-hoc conversion methods128129## Linting130131See `/lint` for linting and formatting workflow.132133---134> Source: [lgtm-hq/ai-skills](https://github.com/lgtm-hq/ai-skills) — distributed by [TomeVault](https://tomevault.io).135<!-- tomevault:4.0:skill_md:2026-06-16 -->
Run npx skillmds@latest add tomevault-io/lgtm-hq-ai-skills-stand-rust in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Rust Standards It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.