Google has released an official style guide for Rust programming language usage across its internal codebases, according to documentation published on its website. The guide establishes consistency standards for Rust code used in multiple Google projects, including Chrome, Android, ChromeOS, and Fuchsia.

The style guide addresses three primary goals shared by most style guides: consistency, readability, and encouraging good API design. However, Google adds a fourth goal specific to large-scale development: smoothing the way for Large-Scale Changes (LSCs)—codebase-spanning refactorings that require tooling assistance. According to the guide, consistency and refactor-friendly code patterns help tooling work more effectively.
The guidance covers both library and application code, with different approaches for each. For library code, API design rules are mandatory. For application code, API design guidelines are strong recommendations but secondary to simplicity and directness, with the guide cautioning against premature generalization and abstraction.
Key recommendations include preferring small crates in Chromium (ideally single-file crates focused on one abstraction), organizing source files within a single directory rather than subdirectories, and naming leaf modules after their primary user-defined items. The guide also specifies patterns for imports, advising against glob imports except in specific situations like inline modules, enum method bodies, and re-exports from non-leaf modules.
Design patterns covered include using #[derive()] attributes when possible, employing #[non_exhaustive] on publicly exposed enums and public structs, applying #[must_use] on functions and types, and preferring expect over unwrap for error handling.
The style guide notes that its rules deviate from standard Rust style guidelines in some cases to accommodate Google’s specific needs around large-scale refactoring and the massive scale of its codebases. The guide also recommends following official public Rust style rules where they don’t conflict with Google’s guidance.
Key facts
- Google published a Rust style guide for internal use across Chrome, Android, ChromeOS, Fuchsia, and other projects
- The guide establishes consistency, readability, and API design standards with an additional focus on Large-Scale Changes (LSCs)
- Library code API design rules are binding; application code rules are strong recommendations
- Recommendations include preferring small single-file crates, avoiding subdirectories for single crate organization, and limiting glob imports
