Rust Style Guide
- ID
- 38685
- Status
- summarized
- Published
- 22 Oct 2026, 3:11 AM
- Fetched
- 23 Oct 2026, 4:59 PM
- Provider
- Hacker News
- Category
- dev-community
- Original URL
- https://google.github.io/styleguide/rustguide.html
- Source URL
- https://hnrss.org/best
Summary
- Score
- 6.0
- Created
- 23 Oct 2026, 5:01 PM
- Tags
- Audience
- developers
What happened
Google published its internal Rust Style Guide as part of the Google Style Guides, and it goes well past formatting: code organization (prefer small crates, flat file layout for rust_library sources, no glob imports), ownership (avoid Rc and Arc, prefer borrows over deep copies), API design (accept Into, prefer enum over bool, #[non_exhaustive] on public enums and public-field structs), error handling, traits, macros and naming. Some rules are explicitly scoped to Google codebases — no async/.await and no std-library threads in [chrome], fuchsia_sync::Mutex for [Fuchsia] — and the implementation section pushes expect over unwrap and warns against panic::catch_unwind and long iterator-combinator chains. It drew 382 points and 249 comments on Hacker News.
Why it matters
This is a concrete, opinionated rulebook you can diff against your own lints rather than a general 'best practices' post: the enforceable ones are things like expect over unwrap, no glob imports, one module per use statement, #[must_use] and #[non_exhaustive] on public types, and no code before main(). Copy the rules that are context-free, but skip the Chrome/Fuchsia-tagged ones — banning async/.await and std threads is a Google-runtime constraint, not a default for a normal service or CLI. There is no Malaysian or SEA angle in this item; its value here is purely code-review and lint-config hygiene for teams shipping Rust.
Discussion angle
Go through the three most contestable rules — avoid Rc/Arc, expect over unwrap, no glob imports — and ask who would actually enforce each as a clippy/CI lint, and where the [chrome]/[Fuchsia] tags mean the rule does not transfer to your codebase.