18 lines | 1.5 KB

description: Idiomatic Rust API design (official Rust API Guidelines) globs: ["**/*.rs"] alwaysApply: true

  • RFC 430 casing: UpperCamelCase types/traits/variants, snake_case fns/modules/macros, SCREAMING_SNAKE_CASE consts; acronyms are one word (Uuid).
  • Getters drop get_ (fn name(&self)); reserve get for the obvious single accessor.
  • Conversions by cost: as_* free, to_* expensive, into_* consuming. Use From/TryFrom/AsRef/AsMut; never hand-write Into/TryInto.
  • Iterators: iter / iter_mut / into_iter returning Iter / IterMut / IntoIter.
  • Derive common traits eagerly: Debug, Clone, Copy, PartialEq/Eq, PartialOrd/Ord, Hash, Default; add Display for human output.
  • Collections implement FromIterator + Extend; gate Serde behind a serde feature; keep types Send + Sync where possible.
  • Error types implement std::error::Error + Send + Sync + 'static. Drop never panics or blocks — use close()/flush() -> Result.
  • Newtypes for static distinctions; enums/structs over bare bool/Option args; bitflags for 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 ?, not unwrap().
  • Feature names have no placeholders (std, not use-std); crate names avoid -rs/-rust.