Introduction

Rust is a programming language focused on performance and memory safety. It offers similar runtime performance to C and C++, but prevents buffer overflows and data races without a garbage collector through stronger compile-time checks.

fn main() {
    println!("Hello, world!");
}

You can try Rust with zero setup in the playground.

Learning Resources

Getting Started

If you are first starting out with Rust, I recommend reading “The Rust Programming Language” book available online. I read the first edition and most of the second edition and it covers everything you need to get started and understand the fundamentals. It contains example projects to work through as well as comparisons to other languages. The “Learn” page on the official Rust website contains other resources in case reading a book is not your thing.

Next Steps

Once you’ve learned the fundamentals of Rust, there are tons of resources to explore depending on the type of program you want to write.

If you want to write a simple command line interface (CLI) program, the Rust CLI Working Group put together a small book. It recommends crates (aka libraries) to write ergonomic and well-documented CLIs, as well as crates for testing.

While you are writing your Rust programs, the Rust compiler will provide tons of feedback :) Every compiler error has additional information, including correct/incorrect examples, to help you better understand the error. e.g. rustc --explain E0382. In addition, I strongly recommend setting up clippy as soon as possible on your projects. It guides you to writing idiomatic and performant APIs through static analysis.

If you are looking for example code in various domains (e.g. error handling, files, threads), Rust by Example contains dozens (if not hundreds) of small snippets and example programs.

Rust has become popular for writing WebAssembly (wasm) web applications because Rust has a rich ecosystem and does not have a garbage collector. The “Rust And WebAssembly” Book teaches you everything you need to know to get started writing Rust wasm web apps by walking you through an interactive Conway’s Game of Life tutorial built in Rust compiled to wasm with a TypeScript-based UI.

Rust competes with C++ and Go for writing fast I/O-bound applications. Rust’s async ecosystem has matured tremendously in 2020 after the stabilization of async/await. Tokio is arguably the most popular async framework and has a great tutorial to help you learn the ins and outs of using Tokio to write multi-threaded Rust code.

If you want to publish your own crate, look over the Rust API Guidelines. It covers tips for making your code easier to use and debug in other programs, including writing effective documentation and versioning your APIs.

Advanced

If you want to learn more about Rust’s Package manager, cargo, “The Cargo Book” explains the Cargo.toml file format, workspaces, profiles, build scripts, and more.

“The Rust Performance Book” contains mostly Rust-specific performance tips.

Reference

Tooling

To quickly add, remove, and upgrade dependencies, I use Cargo Edit. Fun fact, I wrote the original implementation of cargo rm.

I use Visual Studio Code as my preferred editor for writing Rust applications. The Rust Analyzer extension is a must and provides fantastic intellisense, editor hints for running individual tests, auto imports, parameter hints, and more. Seriously, VS Code + Rust Analyzer is an amazing combination. I also use the crates extension to show me outdated dependencies when viewing Cargo.toml files in VS Code.

Crates

  • StructOpt
    • “parse command line arguments by defining a struct”