GeekNews
Google's Rust Style Guide
SoftwareFirst seen 29 points2 comments
Google has published a style guide for writing Rust, a programming language. It explains how Google engineers should write Rust code so that it stays clear, consistent, and easy to change.
What Google published
Google wrote a style guide for Rust code used across its many products. The guide covers more than formatting. It also gives advice on how to design APIs (the ways that code parts connect to each other) and how to build the code inside.
Where Rust is used at Google
Rust is used in many Google projects, including google3, Android, ChromeOS, Fuchsia, and Chrome. Google wants Rust code to look the same inside one project and across projects. Consistent code also helps set a standard of quality.
Why the rules exist
Google says the rules serve a few goals. The code will be used for a long time, so extra care while writing is worth it if it makes the code easier to read. The rules also make Large-Scale Changes (LSCs), which are big updates to many files at once, easier to do with tools. Google also follows the public Rust style rules wherever it can, so new engineers do not have to learn something completely different.
Key points for readers
- Library code must follow the API design rules. Application code should follow them as a strong suggestion.
- Application code should favor simple, direct solutions over code made for many uses too early.
- In Chromium, Google prefers small crates (units of compilation), ideally one file each.
- Where the Google guide and the public Rust rules conflict, the Google guide wins.
Glossary
- Rust
- A programming language focused on safe and fast code.
- Large-Scale Changes (LSCs)
- Big code updates that touch many files at once, often done with tools.
- Android
- Google's mobile operating system for phones and other devices.
- ChromeOS
- Google's operating system based on the Chrome browser.
- Chromium
- The open-source browser project that Google Chrome is built from.