Example Code and Templates
Small Examples and Exercises
- Rust by Example↗: Learn Rust features with small, targeted examples. Starting with "hello world" and moving up to more complex features like traits and generics.
- Rustlings↗: Small exercises to get you used to reading and writing Rust code, including reading and responding to compiler error messages.
- 100 Exercises to Learn Rust↗.
- Advent of Code↗: Language-agnostic programming challenges that can be done in Rust.
- Exercism↗.
- Project Euler↗: Language-agnostic programming challenges focused mostly on math problems.
- Rust by Practice↗.
- The Rust Cookbook↗: A collection of simple examples that demonstrate good practices to accomplish common programming tasks, using the crates of the Rust ecosystem. Some examples are outdated.
- Rust Mastery Exercises↗.
- Rust Quizz↗.
- Rust Practice Questions↗.
- Top 15 Rust projects to elevate your skills: Rust Practice Projects↗.
You can use the Rust Playground↗ to quickly test snippets of code.
Notable Rust Code Repositories
Reading code is the fastest way to learn idiomatic Rust. Use the following links to locate useful Rust repositories.
Lists of Popular Rust Repositories
- GitHub Topic: "Rust"↗: Popular repositories on GitHub.
- Trending GitHub repos↗.
- Awesome Rust↗: A large curated list of Rust resources, including code examples.
- Open-source Projects Categorized as "Rust"↗ (
libhunt.com
). rustrepo.com
↗: A curated list of awesome Rust resources.- Top 100 Best GitHub Repositories for Rust↗.
"RealWorld" Examples
The "Real World" Example App↗ (website)↗, dubbed "the mother of all demo apps", is a fullstack medium.com
↗ clone implemented in many languages and frameworks. A list of Rust implementations is found here↗.
For example, realworld-rust-axum-sqlx
↗ is a full-stack RealWorld implementation using axum
↗, sqlx
↗, and yew
↗.
ChromeOS Virtual Machine Monitor
The ChromeOS Virtual Machine Monitor (github)↗ is written in Rust, with over 300k LoC. Its repository contains many well-documented crates. There is a book↗ and thorough documentation↗ for all crates.
Build Your Own X
Build Your Own X↗ is a compilation of well-written, step-by-step guides for re-creating your favorite technologies from scratch. It includes several Rust projects.
Source Code for Rust Books
You may also consult the code examples from various Rust books:
- Code↗ for the "Zero to Production in Rust"↗ book.
- Source Code↗ for "Practical Rust Web Projects↗: Building Cloud and Web-Based Applications", 1st ed., by Shing Lyu.
Templates
cargo-generate
↗ helps you get up and running quickly with a new Rust project by leveraging a pre-existing git
repository as a template.
You will find cargo-generate
-ready templates in this list↗. Beyond cargo-generate
, search for Rust projects on GitHub↗.
For example, you will find a full template for a REST API written in Rust, engineered for maximum testability in the rust-rest
↗ repo.