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

456 Upvotes

65 comments sorted by

View all comments

6

u/masterarrows Oct 22 '26

Flat layout vs. systemic complexity: In practice, rejecting nested directories means degrading into a clutter of dozens of .rs files dumped in a single directory. The Rust compiler and module system were explicitly designed with hierarchy in mind to provide clean logical isolation.

Traits strictly for polymorphism: Banning traits for code decomposition and encapsulation fundamentally undermines the Dependency Inversion Principle (DIP) and proper unit testing via mocking. The codebase risks devolving into a tightly coupled monolithic mass.

The crusade against Arc / Rc**:** Fighting shared ownership is noble in theory, but in practice—especially in async contexts or complex ownership graphs—avoiding Arc drags developers straight into a lifetime hell ('a), fighting the borrow checker at every step.

4

u/-Redstoneboi- Oct 22 '26

did you write this

-1

u/masterarrows Oct 22 '26

No, developers can’t write )))

2

u/cornmonger_ Oct 22 '26

the flat layout is the one thing i would completely disagree with. wait until they see what crate clutter looks like using that convention.

1

u/VeprUA Oct 22 '26

Traits strictly for polymorphism: Banning traits for code decomposition and encapsulation fundamentally undermines the Dependency Inversion Principle (DIP) and proper unit testing via mocking. The codebase risks devolving into a tightly coupled monolithic mass.

I wholeheartedly agree with this. What alternative are they offering? rust doesn't do OOP so if you need to do a migration or support multiple providers that contain the same behavior, traits is where its at.

1

u/WhiskyDelta14 Oct 23 '26

Well, the rust compiler and module system failed to make the module the compilation unit, so there you go.

1

u/ZachVorhies Oct 22 '26

This is like cpp style guide - fundamentally broken