This repository collects resources for writing clean, idiomatic Rust code. Please bring your own. 😊
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
-
Programming an ARM microcontroller in Rust at four different levels of abstraction by Pramode C.E - Demonstrates how Rust helps to move from brittle, low-level embedded code to high-level abstractions with zero cost.
-
Discover the world of microcontrollers through Rust! - This book is an introductory course on microcontroller-based embedded systems that uses Rust as the teaching language rather than the usual C/C++.
- Lessons learned redesigning and refactoring a Rust Library by @mgattozzi -
RefCell
, the builder pattern and more. - Math with distances in Rust: safety and correctness across units by @code-ape - How to create a system to cleanly and safely do arithmetic with lengths.
- The balance between cost, useability and soundness in C bindings, and Rust-SDL2's release by @Cobrand - Writing safe, sound, idiomatic libraries despite the limitations of the borrow checker.
- Russian Dolls and clean Rust code by @mgattozzi - How to use the full power of
Option
andResult
(especiallyand_then()
andunwrap_or()
). - Elegant Library APIs in Rust by @killercup - Many helpful tips and tricks for writing libraries in Rust.
- Teaching libraries through good documentation by @killercup - How to use the full power of Rust's documentation support (e.g. doc tests)
- Pretty State Machine Patterns in Rust by @hoverbear - How to represent a State Machine in an expressive and understandable way in Rust.
- Ripgrep Code Review by @mbrt - An analysis of the popular
ripgrep
tool's source code. - Rustic Bits by @llogiq - Small things that make for rustic code.
- Convenient and idiomatic conversions in Rust by meqif - Explains
From<T>
,Into<T>
,TryFrom<T>
,TryInto<T>
,AsRef<T>
andAsMut<T>
with pratical examples. - Idiomatic tree and graph like structures in Rust by saschagrunert - Introduction to safe, dynamic, arena based tree structures without using lifetimes.
- Rust traits for developer friendly libraries by @benashford - Thoughts about implementing good Rust libraries.
- Error Handling in Rust by @BurntSushi - Understanding and handling errors in Rust in an idiomatic way.
- Creating a Rust function that accepts String or &str by @hjr - How to make calling your code both ergonomic and fast (zero-allocation).
- Creating a Rust function that returns a &str or String by @hjr - How
Into
andCow
(Clone-on-write) work together to avoid allocations for string types. - Effectively Using Iterators In Rust by @hjr - Explanation of the
Iter
andIntoIter
traits and how loops actually work in Rust. - Strategies for solving 'cannot move out of' borrowing errors in Rust by @hjr - Practical tips to help understand the borrow-checker and move semantics.
- Rayon: data parallelism in Rust by @nikomatsakis - Writing elegant parallel code in Rust.
Idiomatic Rust - Writing Concise and Elegant Rust Code [Video] [Slides] by @mre - FOSDEM 2018
Idiomatic Rust Libraries [Video] [Slides] by @killercup - Rustfest Kiev
What's so hard about writing a Slack Client in Rust? [Video] [Slides] by @mre - Rust Cologne Meetup
- Rust Anthology - The best short-form writing about Rust, collected.
- clippy - A bunch of lints to catch common mistakes and improve your Rust code.
- Patterns - A catalogue of Rust design patterns.
- Rust by Example - A community driven collection of example code which follow Rust best practices.
- Rust Cookbook - Examples that demonstrate good practices to accomplish common programming tasks in Rust.
- rust-api-guidelines - An extensive list of recommendations for idiomatic Rust APIs.
- Which is more idiomatic? Functional, imperative or a mix?
- An idiomatic way to sum up values in a multidimensional Array
Coming from Python I loved to have some 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.
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. If this becomes a thing I plan to move it to some "semi-official" place like rust-nursery or so. But first I need YOUR help for that ;-)
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.