Rust Guide
Rust is a systems level programming language with an emphasis on performance, reliability, productivity, and readability. It has the low level performance of C or C++ without the danger of pointer problems. It is able to do this, because it's compiler ensures any potential errors aren't added (you can think of it as having a garbage collector at the compile stage).
Rust can be used for server side software, embedded devices, websites (via WebAssembly), and much more as the community continues to grow. The official documentation (a.k.a. The Book) does an excellent job at introducing someone familiar with programming to Rust.
Getting Started
Rust is known for having a steep learning curve.
As with any programming language, the best way to learn Rust is by doing a Rust.
Following along with The Book and attempt each exercise.
If you can make it to Chapter 12, you should be well on your way to learning Rust.
Attempt to make simple applications in Rust, like the Unix head
utility.
If you have issues, feel free to ask other members.
(We love any chance to talk about Rust.)
Above all else, remember that the Rust compiler is the best kind of friend;
when other compilers would turn a blind eye and let you hurt yourself, rustc
will jump in and say, "Woah buddy! Have you thought this through?"
Friends like rustc
can be annoying at times, but they're the friends you want to be with.
Beyond The Book, there are a number of great Rust resources for developers of all skill levels. See Resources below.
Note on Installation
We recommend that you install the Rust toolchain via rustup.
While many Linux distributions offer Rust packages, these pacakges can often be outdated.
Installing rustup
circumvents this problem entirely.
Resources
- Official Website
- Official Documentation (The Book) - We can't mention this one enough. Go-to resource for Rustaceans of all skill levels.
- Setting up your editor
- Official Cargo Documentation - Rust has a mature package manager / build system that combines the best of
npm
andmake
. Once you usecargo
, you'll never look at project management the same way. - Rust by Example - Similar to The Book, but with less talk and more code.
- Learn Rust with Entirely Too Many Linked Lists - A great (and humorous) introduction to Rust's memory management scheme. Highly recommended for anyone who knows the basics of Rust, but hasn't gotten a handle on lifetimes and the ownership model.
- Rust Cookbook - "How do I do ___ in Rust?" (also shows off a number of community standard crates)
Good Rust Talks
- Rust: A Language for the Next 40 Years - Explanation of the Rust's safety guarantees and the goals of the Rust project.
- Procedural Macros - Good introduction to procedural macros.
- Zero Cost Async IO - Review on the current state of asynchronous Rust in 2019. (See also: tokio)
- I Convinced the World's Largest Package Manager to Use Rust, and So Can You - how npm began using Rust
Game Libraries
- piston - Most popular Rust library for game development.
- amethyst - The second most popular Rust library.
- Bonus: Rust at Chucklefish - Developers of Starbound and Stardew Valley published this whitepaper, explaining why they chose to develop their next title with Rust. Well, a former developer later stated that they moved from Rust back to their C++ engine, since, "it just didn't make much sense for a small company to be developing two engines in parallel, instead of re-using existing code and knowledge." Understandable.
See also: "Are we ___ yet? section below.
WebAssembly
rustc
is based on LLVM, meaning that it can generate WebAssembly (WASM) code with relative ease.
Add in the wasm-bindgen
crate, and you have all the safety of Rust, with the speed of WASM, and the convenience of JavaScript.
- Tensor Programming - Intro to Rust Web Asssembly - Great YouTube tutorial explaining how to compile Rust to WASM from start to finish.
- wasm-bindgen Documentation - Official documentation for the wasm-bindgen crate. Includes instructions for compiling Rust to WASM, and instructions for calling JavaScript functions from Rust using
web-sys
. - WebAssembly with Rust - Excellent talk from Kevin Hoffman, who literally wrote the book on Rust+WASM. Explains many WASM fundamentals well.
- Yew - A Rust framework for front-end web development inspired by Elm.
Graphics
- gfx-hal - An ambitious, low-level Rust library that based in part on Vulkan. Not for the faint of heart.
- Review of Rust Graphics Libraries (2019) - Review of graphics libraries in Rust.
See also: the "Are we ___ yet?" section below.
Benchmarking Rust
- Perf - If you're a Linux user you should consider using
perf
. Based on a Linux kernel interface,perf
directly tracks different events like cache misses, cpu-cycles, and branches. Thus,perf
gives you a hardware-independent profile of your program's performance. - cargo-bench - Official documentation on the "cargo bench" command. Note that the stable toolchain does not include a benchmarking crate by default, so you will need to add a crate to your project (see below).
- criterion.rs - A Rust crate offering sophisticated benchmarking, based on Haskell's Criterion library. At the time of writing, this library seems poised to become the standard.
- Paul Mason - Benchmarking and Optimization of Rust Libraries - Relevant talk from RustConf 2018.
Operating Systems
Remember that part about Rust being 'low level'?
- Redox - Unix-like operating system rocking a custom libc and microkernel design.
- Writing an OS in Rust - Great blog series with code snippets and explanations of common OS concepts.
- Relevant: The Embedded Systems Book
Text Parsers
- nom - High-performance text parsing crate with a bottom-up approach. (See also: unofficial tutorial)
- pest - "the elegant parser" emphasizing accessibility. Similar in spirit to ANTLR.
- antlr4-backend: coming soon??? - The king of all parser-generators might have a Rust target soon. Stay posted.
Other Neat Crates
- rand - Rust's standard library does not include any random number generators.
rand
is the de facto standard for RNGs. - clap - Extremely versatile command-line argument parser.
- serde - Efficient serialization framework for Rust.
- ripgrep - Took the title for "fastest grep" from the long-reigning champion GNU grep.
- rust-bio - library of common bioinformatic alogrithms and data structures
- flate2 - library for compression / decompression (gzip and zlib formats)
- tokio - reliable, high-performance asynchronous runtime for Rust
- futures - zero-cost asynchronous Rust
"Are we ___ yet?"
Rust has a small standard library, but a big community that grows every day. These pages track Rust's development in different domains of interest.
- Are we async yet? - Stablized syntax, robust ecosystem, more features coming every day (Feb 2020).
- Are we web yet? - Can we build a backend in Rust? (Spoiler: yes.)
- Are we game yet? - Libraries relevant to game developers.
- Are we GUI yet? - Cross platform GUIs in Rust are still in development.
- Are we learning yet? - Current state of machine learning in Rust.