Rust Style Guide(google.github.io)
378 points by kaycebasques 4 days ago | 247 comments
tl;dr: Google has published its internal Rust style guide, covering formatting, API design, code organization, and implementation patterns, with specific carve-outs for Chromium, Android, and Fuchsia codebases. Key opinions include preferring small crates with flat file layouts, avoiding `Rc`/`Arc` and glob imports, using `expect` over `unwrap`, favoring iterators over owned collections in library APIs, applying `#[non_exhaustive]` to public enums/structs, and banning `async`/`.await` in Chromium. The guide emphasizes readability, enabling large-scale refactors (LSCs), and consistency with the broader Rust ecosystem where possible.
HN Discussion:
  • ↓Applying #[non_exhaustive] to enums undermines compile-time exhaustiveness checking benefits
  • ↓The tiny-crates/no-nested-modules rule seems like harmful over-abstraction similar to tiny-functions trend
  • ↓Unqualified type imports create redundant naming and reduce code readability without IDE help
  • ↓Google's recommendations no longer carry special authority compared to other big tech companies
  • ↑Having a coherent, consolidated style guide is valuable and appreciated