HeadlinesBriefing HeadlinesBriefing.com

Google's Rust Style Guide: Rules for Consistent Code

Hacker News •
×

Google has published its Rust Style Guide, a document governing how Rust is written across Google's codebases, including google3, Android, Chrome OS, Fuchsia, and Chrome. The guide covers more than formatting, extending to API and implementation design. Its stated aim is consistency in Rust usage both within and across these codebases, while also establishing a standard of quality.

The guide's scope of authority varies by project. Android, Chromium, and other codebases were consulted in its development and intend to begin applying it, though each may set its own rules on how strictly the guide is enforced. Information on that adoption is expected to follow as those codebases adopt it.

The guide's goals largely mirror those of Google's C++ style guide. Most of its rules trace back to one or more of these goals, with readability and maintainability given priority over writeability. The authors note that code is expected to remain in use for long periods, so a small amount of extra effort in writing it is considered worthwhile.

The document is organized into sections covering code organization, formatting, ownership and borrowing, function inputs and outputs, types, traits, generics, concurrency, naming, documentation, unsafe code, and implementation concerns. Guidance includes preferring small crates, avoiding glob imports, avoiding Rc and Arc, and preferring enums over bools in APIs.

Source: Hacker News · Summarized by HeadlinesBriefing