This repository collects resources for writing clean, idiomatic Rust code. You can find a sortable/searchable version of this list here.
Idiomatic coding means following the conventions of a given language. It is the most concise, convenient, and common way of accomplishing a task in that language, rather than forcing it to work in a way the author is familiar with from a different language. - Adapted from Tim Mansfield
Contributions welcome! To add missing resources, please refer to the contributing documentation.
- blessed.rs β An unofficial guide to the Rust ecosystem. Suggestions for popular, well-maintained crates.
 - cheats.rs - Idiomatic Rust tips β A list of quick tips to make your code more idiomatic.
 - clippy β A bunch of lints to catch common mistakes and improve your Rust code.
 - Elements of Rust β A collection of software engineering techniques for effectively expressing intent with Rust.
 - Patterns β A catalogue of design patterns in Rust.
 - Possible Rust β A blog for intermediate Rust programmers exploring real-world code and design patterns.
 - Rust Anthology β The best short-form writing about Rust, collected.
 - Rust API Guidelines β An extensive list of recommendations for idiomatic Rust APIs.
 - Rust by Example β A community driven collection of example code which follow Rust best practices.
 
- Build your own JIRA with Rust β A test-driven workshop to learn Rust by building your own JIRA clone!
 - Comprehensive Rust β A four day Rust course developed by the Android team, covering all aspects of Rust.
 - Ferrous Systems Teaching Material β Free workshop material produced by Ferrous Systems for trainings.
 - Hecto: Build your own text editor in Rust β This is a series of blog posts that shows you how to build a text editor in Rust
 - Idiomatic Rust Workshop β A talk/workshop about idiomatic Rust code focusing on effective use of existing syntax and design patterns
 - PingCAP talent plan β A series of training courses about writing distributed systems in Rust.
 - Procedural Macros Workshop β A selection of projects designed to learn to write Rust procedural macros.
 - Rust 101 β A Rust University course by tweede golf.
 - Rust Development at Sentry β A document containing useful resources for getting started with Rust and adhering to Sentry coding principles.
 - rust-lang/rustlings β Small exercises to get you used to reading and writing Rust code.
 
- Command Line Applications in Rust β A tutorial on how to write CLI apps in Rust, learning many aspects of the ecosystem.
 - Command-Line Rust β Learn the language by writing Rust versions of common Unix coreutils.
 - Discover the world of microcontrollers through Rust! β An introductory course on microcontroller-based embedded systems using Rust.
 - High Assurance Rust β Developing secure and robust software, focusing on embedded-friendly data structures in Rust.
 - Programming Rust: Fast, Safe Systems Development β A comprehensive Rust Programming Guide that covers most of Rust's features in detail.
 - Rust Atomics and Locks β Helps Rust programmers of all levels gain a clear understanding of low-level concurrency.
 - Rust Cookbook β Examples that demonstrate good practices to accomplish common programming tasks in Rust.
 - Rust for Rustaceans β Covers how to design reliable, idiomatic, and ergonomic Rust programs based on best principles.
 
- Aim For Immutability in Rust β Explains why variables are immutable in Rust by default.
 - Compile-Time Invariants in Rust β Shows how macros can be used to enforce invariants at compile-time.
 
- Hexagonal architecture in Rust β Describes how to build a Rust service using domain driven design and a test-first approach.
 - Wrapping errors in Rust β Wrapping 'reqwest::Error' and a custom error type as an enum to make library usage easier.
 - Aiming for idiomatic Rust β Discusses different ways to solve a popular coding puzzle, 'balanced brackets', in Rust.
 - Naming Your Lifetimes β Explains how using longer, declarative lifetime names can help to disambiguate which borrow is which.
 
- Are out parameters idiomatic in Rust? β Discusses the pros and cons of functions returning a value vs. modifying a parameter in-place.
 - Guide on how to write documentation for a Rust crate β Writing good documentation with rustdoc including many examples.
 - Learning Rust through open source and live code reviews β Covers patterns like 'FromStr' and exposing a CLI and a library in one crate.
 - Refactoring Rust Transpiled from C β Describes how to lift a C-project that was automatically converted to unsafe Rust to safer, more idiomatic Rust.
 - Context-preserving error handling β Explains how to use crates like 'thiserror' in combination with 'map_err' to add context to errors.
 
- Rust Patterns: Enums Instead Of Booleans β Discusses how using enums instead of booleans can express intent more clearly in Rust.
 - Taking string arguments in Rust β Discussing how to avoid subtle issues with string handling and when to use 'str' vs 'String'.
 - Await a minute β Example code for moving from raw futures to async/await syntax to improve error handling.
 
- Programming an ARM microcontroller in Rust at four different levels of abstraction β Demonstrates how Rust helps to move from low-level embedded code to high-level abstractions.
 
- The balance between cost, useability and soundness in C bindings, and Rust-SDL2's release β Writing safe, sound, idiomatic libraries despite the limitations of the borrow checker.
 - Math with distances in Rust: safety and correctness across units β How to create a system to cleanly and safely do arithmetic with lengths.
 - Lessons learned redesigning and refactoring a Rust Library β 'RefCell', the builder pattern and more.
 - Iteration patterns for Result & Option β Explores how to filter and partition iterators of Result and Option types idiomatically.
 
- Idiomatic tree and graph like structures in Rust β Introduction to safe, dynamic, arena based tree structures without using lifetimes.
 - Convenient and idiomatic conversions in Rust β Explains 'From', 'Into', 'TryFrom', 'TryInto', 'AsRef' and 'AsMut' with practical examples.
 - Rustic Bits β Small things that make for rustic code.
 - Ripgrep Code Review β An analysis of the popular 'ripgrep' tool's source code.
 - Pretty State Machine Patterns in Rust β How to represent a State Machine in an expressive and understandable way in Rust.
 - Teaching libraries through good documentation β How to use the full power of Rust's documentation support (e.g. doc tests).
 - Elegant Library APIs in Rust β Many helpful tips and tricks for writing libraries in Rust.
 - Russian Dolls and clean Rust code β How to use the full power of 'Option' and 'Result' (especially 'and_then()' and 'unwrap_or()').
 
- Rayon: data parallelism in Rust β Writing elegant parallel code in Rust.
 - Strategies for solving 'cannot move out of' borrowing errors in Rust β Practical tips to help understand the borrow-checker and move semantics.
 - Effectively Using Iterators In Rust β Explanation of the 'Iter' and 'IntoIter' traits and how loops actually work in Rust.
 - Creating a Rust function that returns a &str or String β How 'Into' and 'Cow' (Clone-on-write) work together to avoid allocations for string types.
 - Creating a Rust function that accepts String or &str β How to make calling your code both ergonomic and fast (zero-allocation).
 - Error Handling in Rust β Understanding and handling errors in Rust in an idiomatic way.
 - Rust traits for developer friendly libraries β Thoughts about implementing good Rust libraries.
 
- The Four Horsemen of Bad Rust Code β A talk about common pitfalls in Rust code like overengineering and premature optimization. [Video]
 
- Tricks of the Trait: Enabling Ergonomic Extractors β Rust Nation UK, Feb. 2023 [Video]
 
- Ergonomic APIs for hard problems β RustLab Conference, October 2022 [Video]
 - Nine Rules for Elegant Rust Library APIs β Seattle Rust Meetup, Sep. 2022 [Video]
 
- Macros for a More Productive Rust β RustConf 2020 [Video]
 
- Making Rust Delightful β RustCon Asia 2019 [Video]
 
- Idiomatic Rust - Writing Concise and Elegant Rust Code β FOSDEM 2018 [Video]
 
- Idiomatic Rust Libraries β Rustfest Kiev [Video]
 
- An idiomatic way to sum up values in a multidimensional Array
 - Which is more idiomatic? Functional, imperative or a mix?
 
Coming from Python, I loved the guidelines on how idiomatic Python looks like. I was inspired by the likes of Peter Norvig, who wrote amazing articles on spellcheckers and sudoku solvers; and, of course, the Zen of Python. For Rust, there is no such thing as the Zen of Python, however, so I started collecting my own resources. The goal of this project is to create a peer-reviewed collection of articles/talks/repos, which teach idiomatic Rust style. It's a community project and you can contribute.
To the extent possible under law, Matthias Endler has waived all copyright and related or neighboring rights to this work. Logo adapted from FreePik.com.

