description: Idiomatic Rust API design (official Rust API Guidelines) globs: ["**/*.rs"] alwaysApply: true
- RFC 430 casing:
UpperCamelCasetypes/traits/variants,snake_casefns/modules/macros,SCREAMING_SNAKE_CASEconsts; acronyms are one word (Uuid). - Getters drop
get_(fn name(&self)); reservegetfor the obvious single accessor. - Conversions by cost:
as_*free,to_*expensive,into_*consuming. UseFrom/TryFrom/AsRef/AsMut; never hand-writeInto/TryInto. - Iterators:
iter/iter_mut/into_iterreturningIter/IterMut/IntoIter. - Derive common traits eagerly:
Debug,Clone,Copy,PartialEq/Eq,PartialOrd/Ord,Hash,Default; addDisplayfor human output. - Collections implement
FromIterator+Extend; gate Serde behind aserdefeature; keep typesSend + Syncwhere possible. - Error types implement
std::error::Error+Send + Sync + 'static.Dropnever panics or blocks — useclose()/flush()->Result. - Newtypes for static distinctions; enums/structs over bare
bool/Optionargs;bitflagsfor flag sets; builders for complex construction. - Validate arguments; keep struct fields private; seal non-downstream traits; mark extensible enums/structs
#[non_exhaustive]; don't duplicate derived bounds on the struct. - Document
# Errors/# Panics/# Safety; rustdoc examples use?, notunwrap(). - Feature names have no placeholders (
std, notuse-std); crate names avoid-rs/-rust.