Google's Rust Style Guide Bans async/await and Arc in Chrome Code
Google has published a Rust style guide that goes beyond formatting to cover API and implementation design. It applies across google3, Android, ChromeOS, Fuchsia, and Chrome, and notably forbids async/await and starting threads via the standard library in Chrome, while discouraging Rc and Arc. The guide prioritizes readability, automation for large-scale changes, and consistency with the wider Rust ecosystem.
Don’t use `async` / `.await`[chrome]
- monocasa
Can anyone expand on the chromium specifc guidelines on super tiny crates, particularly no nesting of modules/source files?
That feels like the ~2010 era of people saying that functions should be as small as possible. That lead me to reviewing a lot of code where every function was one or two lines and you couldn't actually see what was going on anymore through the layers of unneeded abstraction.
I want to give chrome the benefit of the doubt, but that seems really goofy.
- epage
> Type names should be imported and used unqualified
This just pushes people to have redundant information in types (`IoError` instead of `io::Error`).
Unless a type is widely recognized (like `HashMap`), I prefer to have them fully qualified so I have the contextual meaning for it. If I am working with a generic name like `Source`, what does that mean? I shouldn't have to look up in the imports to understand the code (or only understand it through an LSP).
Reducing imports also reduces unnecessary merge conflicts.
- JoeDohn
This is nice, I have been lurking on google and meta rust projects, mimicking and picking style by prompting LLMs to distill it, taking a look at fmt & clippy configs helps too.
But it wasn't as coherent and reliable from project to project like this guide. Kudos to google on this one !
- afdbcreid
Here's a tip most Rust users don't know about extension traits: if you put `#[rust_analyzer::prefer_underscore_import]` above your trait (and you're using rust-analyzer and not RustRover), autocompletion and the import assist will import the trait `as _` by default, which is very useful for extension traits.
- hitekker
> Don’t use async / .await in Chromium.
That's pretty direct. IIRC, the Rust for Linux people also have that refrain informally
- i2talics
Much of this is very standard across the Rust ecosystem but it's very helpful to have it all in one place.
- tcallred
I really appreciate that they distinguish between library code and application code. Rust gets too much of a bad rap for its complicated generic code, but in most application scenarios you are not writing code nearly that complex or generic.
- petcat
At this point, is anybody writing new C or C++? It seems like they are sunset languages even at the big corps.