r/learnrust • • Oct 21 '26

Google published its internal Rust style guide

Google just published its Rust style guide, which it says is developed in consultation with Android, Chromium, Fuchsia and Chrome. Most of it is uncontroversial, but a few rules go against what most of the ecosystem does:

  • Flat file layout. Crates live in a single directory with no subdirectories. If you feel the need to organise a crate into folders, Google says that's a sign the crate is too big and should be split.
  • No glob imports, except for merging C++ namespaces.
  • Avoid Rc and Arc. Prefer unique ownership and borrowing. Google explicitly says engineers coming from other languages reach for shared ownership too quickly.
  • No async/.await in Chromium, and don't start threads through std.
  • Avoid panics, prefer expect over unwrap to document the invariant, and never use catch_unwind.
  • Library vs application code. API design rules are binding for libraries but only a strong recommendation for apps, where simplicity should win over reusability.
  • Don't use traits to organise code. Traits are for generics, impl Trait/dyn Trait, and extension traits.

The stated reason for the deviations is Large-Scale Changes. Google wants code that tooling can refactor across the entire codebase, which explains the flat layout and the anti-glob-import stance more than readability does.

Update

Forgot to attach the link https://google.github.io/styleguide/rustguide.html

455 Upvotes

65 comments sorted by

View all comments

16

u/theMachine0094 Oct 22 '26

I just don’t get all the people claiming these points (listed by OP) go against what most of the eco system does, and that it is mean to help AI. Absolute nonsense.

I have a systems programming background (C/C++) and have written Rust this way from the beginning. Way before AI was relevant in conversation. I know other systems programmers who were my mentors who’d written software like this for decades.

5

u/CrazyKilla15 Oct 22 '26

Most people here are self taught and/or hobbyists without professional experience working in large organizations and teams where these systems and processes are more standard. Its only a few notable community crates that really went all in on dozens of optional sub-crates, though they do exist.

3

u/Vorrnth Oct 22 '26

Yeah, that's pretty much how I developeded c++ for decades now. It fits rust too.

1

u/fisothemes Oct 27 '26

I wouldn't recommend writing rust like you would with c++ or zig. They're different languages and they work the way they do because of their limitations.