Skip to main content

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

Good Rust Talks

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.

Graphics

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'?

Text Parsers

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.