Rust conventions is an AI agent skill from the GitHub repository Goldziher/ai-rulez. Rust code conventions covering edition 2024, cargo fmt/clippy, Result-based error handling, unsafe discipline, async with tokio, API-guideline naming, trait implementations, benchmarking, and security scanning. Load when writing or reviewing Rust code.
Result<T, E> with a derive-based error crate (e.g., thiserror) for library errors, a context-adding error crate (e.g., anyhow) for applications. ? for propagation — never .unwrap() in library code.
Structured logging (spans and events, e.g., the tracing crate) — not println!.
API naming: follow as_/to_/into_ conventions for conversions, iter()/iter_mut()/into_iter() for iterators. Getters are field() not get_field(). See Rust API Guidelines.
Eagerly implement common traits: Clone, Debug, Default, Eq, PartialEq, Hash, Send, Sync. Use From/AsRef/AsMut for conversions, FromIterator/Extend for collections.
Type safety: newtypes for static distinctions, builder pattern for complex construction, bitflags over enums for flag sets. Avoid bool params — use custom types or enums.
Constructors: new() as static inherent methods. No out-parameters. Only smart pointers implement Deref/DerefMut.
API flexibility: minimize parameter assumptions via generics, make traits object-safe when trait objects may be useful. Let callers decide where to copy and place data.
Rustdoc: all public items have doc examples using ? (not unwrap). Document errors, panics, and safety invariants. Hyperlink related items.
Future-proofing: seal traits to prevent downstream implementations, keep struct fields private, don't duplicate derived trait bounds on structs. See Rust Design Patterns.
Anti-patterns: unwrap(), unguarded unsafe, panics in libraries, Vec/HashMap across FFI.
Use this skill with your AI agent:Open on Skill Issue to copy, download, or add to your library.
Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.