liveBook · Manning

Idiomatic coding style

As explained in Idiomatic Rust

A conventional low-level coding practice concerning source-code syntax, formatting, naming, or style within a programming language community.

Idiomatic Rust follows conventions that other Rust programmers can recognize and reason about. Familiar choices make code easier to read and help maintainers judge whether a design fits its purpose. An idiom may be small; it need not be a large design pattern. section 1.0 section 1.2

Treat conventions as tools, not rules. Choose a familiar approach when it clarifies the code, but adapt it when the problem calls for something else. A pattern used in the wrong situation can make a design worse rather than better. section 1.1 section 1.2

When choosing a style for Rust library code:

  • Start with the Rust standard library: inspect its documentation, linked source, and historical discussions to see both a convention and the reasoning behind it. section 6.6
  • Compare popular crates for additional approaches, but evaluate their designs rather than assuming popularity proves quality. section 6.6

How Idiomatic Rust covers it

How deep it goes
Defines idioms broadly and gives sources for investigating conventions, without specifying formatting rules or working through a syntax example.
Examples
Points to standard-library documentation, source, and historical discussions, plus popular crates, as concrete references to inspect.
What it assumes
Assumes some Rust familiarity; beginners can engage but may need other resources when the treatment becomes challenging.
What you can do after
Evaluate/understand conventions in existing Rust code and adapt suitable ones for a project rather than following patterns blindly.
How it connects
Relates idioms to design patterns, antipatterns, library design, and the Rust standard library.

Also explained in

Compare how 3 books explain idiomatic coding style →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Idiomatic Rust. The section links point to the parts of the book it draws on.