Urgent.News

What's breaking now, across thousands of outlets.

Tech

Google's Rust Style Guide

This style guide outlines the guidelines for using the Rust programming language at Google. Rust is used in various Google codebases such as google3, Android, ChromeOS, Fuchsia, and Chrome. The goal is to maintain consistency in Rust usage across different codebases and improve code readability. The style guide shares the three common goals of other style guides: consistency, readability, and encouraging good API design.

An additional goal is to make it easier for Large-Scale Changes (LSCs) by promoting deliberate refactor-friendly patterns.

For library code, style guide rules concerning API design are binding. For application code, the rules on API design are a strong recommendation, with a focus on simplicity and directness over broad reusability. Avoid premature generalization and abstraction, and focus on meeting immediate needs.

In Chromium, it is preferred not to split modules across files. Small crates, ideally single-file crates focused on one abstraction, are recommended. If using submodules, follow the expected file structure. However, larger crates with trait impl coherence rules or foundational libraries are allowed.

Files belonging to a single rust_library (Rust crate) must reside in a single directory. Avoid using subdirectories to organize files within a single crate. If organizing files in subdirectories seems necessary, it indicates the crate has grown too large and should be split. This approach differs from the conventional Cargo directory structure used in open-source repositories. For Rust code in //third_party that is also built with Cargo, the conventional Cargo directory structure should be followed.

Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Also reported by 1 other outlet

Read the original at google.github.io →

More in Tech

More from Wednesday 21 October →