Rust
Programming Language
Links

Rust is what C++ should have been,
had it not escaped Bell Labs prematurely

Updated: 20 July 2023

Contents:

Learn Rust

Of course, begin with resources on the Rust programming language website: https://rust-lang.org/

There is a handy cheat sheet (and A (type-based) Rust cheatsheet), and SVG poster in addition to The Rust Language Reference and The Rust Language Grammar. Both continue as works-in-progress 3 years after 1.0-stable (released May 2015) with pull-requests or filing issues welcomed: reference or grammar.md, respectively.

Coming from C/C++? Learn Rust the Dangerous Way.

Reference to the Rust Standard Library, run:

rustup doc --std

Similarly, for the de facto tutorial, TRPL (2nd Ed), run:

rustup doc --book

While there’s much to appreciate and respect about it, its style may seem verbose for some.

Now, there’s an abridged 3600 word version: Summary of The Rust Book, which addresses the critique below.

The mainline edition of The Rust Book is a work-in-progress despite having a couple of dead-tree versions.

Critique:

In technical writing, conventional practice introduces new material by directly stating the most novel concepts for the audience first, followed by elaboration and examples.

By contrast, TRPL 1st and 2nd Edition use a narrative flow typical of many bloggers, where there’s a build-up of anticipation followed by a reveal of substance. The single most useful sentence– or sometimes, phrase– within each section stating the actual idiom often gets lost within their storytelling style.

Bridging such differences: they would do well by highlighting language idioms in a sidebar (or just a bold font, inline) for each subsection.

This would preserve integrity of their writing style while accommodating both a more diverse audience and readers returning to find just the one tidbit of interest.

For those who grew up with the likes of K&R C lovingly within reach, there is another book a bit closer, in that it states an idiom first and then its companion example or explanation:

Highly recommended book: Programming Rust, 2nd Ed.

(No affiliation with the authors, publisher or sellers)

For both 1st & 2nd Editions:

Blandy’s & Orendorff’s Programming Rust is the closest to a K&R C book for the Rust programming language so far.

It’s concise. It begins with the key concepts. It’s organized suitably for the pragmatic software developer with a dev-ops mindset.

For working through actual code, the canonical book for that is: Rust by Example (RBE).

Discuss on Discord. (Since the official Mozilla IRC service has been sunset, there is an unofficial #rust on Freenode.)

Stay Current

Rust Search Extension – browser extensions:
“Search docs, crates, builtin attributes, official books, and error codes, etc in your address bar instantly. Input keyword rs then press Space to get started.”

This Week In Rust
Follow Rust programming language and community updates. Reading just this one is likely enough for most people, as they aggregate all of the other major resources.

Official blog

Announcements on The Rust Programming Language Forum

Track possible/pending features within The Unstable Book, but note that many items in there may never reach stable. Also, remember to annotate any code using these features with: #![feature(foo_feature)].

Likely to be covered on one of the above websites when it’s news, but complete collection of confirmed vulnerable exploits: RustSec advisory-db

Attend Rust Conf or Rust Belt Rust. Follow conf activity via Twitter #rustconf or IRC #rustconf.

Employment

These yielded solid leads and jobs for the maintainer of this list:

Others for which the maintainer of this list has no direct experience:

Overcome & Persevere

Certain language features are challenging even for those who may believe they’ve grasped the core concepts.

Here are some resources found to be helpful.

If Rust has a golden rule, consider it being “Whenever the body of a function contradicts the function’s signature, the signature takes precedence; the signature is right and the body is wrong.” This gets explained with more detail and examples in Steve Klabnik’s 2023 posting.

Beware of silent integer overflows:
Instead of operators like a + b * c, use methods like .checked_add(). For instance, let mut x:u8=255; x+=100; produces difference behaviour when compiled via cargo build with and without --release flag. It will panic without the flag, and silently overflow/wrap-around with the release flag. This is because the default case suits the fast path for low-level hardware. There is virtually no additional overhead for these methods, when examining the generated Assembly language code.
Alternatively, use a BigNum library such as one built upon GNU Multiple Precision (GMP) like gmp-mpfr-sys or “a big integer library with good performance,” ibig-rs.

Introduction to the mindset used by Rust:
Rust Means Never Having to Close a Socket from pre-1.0 Rust (Oct 2014) yet still relevant with newer editions for concepts explained.

Be sure to also read at least the introductory chapters of The Rustonomicon, even if you have no intention of ever using unsafe code. Explanations given there provide a more diverse perspective on ownership, borrowing, lifetimes, variance (Vlad’s answer may help explain concepts behind the jargon), drop check, etc.

Inside Rust Blog

Selection of forum posts, such as from Stack Overflow and Reddit:

A catalogue of Rust design patterns
Even for those coming from one of the Lisp languages/dialects and agree with Rich Hickey that patterns mean you’ve “run out of language,” this list is still quite valuable. (And yes, Rust has robust Macros that accommodate many of the use cases for which Common Lisp macros are actually used.)

Podcasts:

Tokio

An event-driven, non-blocking I/O platform for writing asynchronous I/O backed applications:

Futures, async/await

See The Async Book (and GitHub repo)

As of Rust v1.39 (November 2019), async/await landed in stable.

Achieve high concurrency with Rust using far more workers than total number of OS heavyweight threads or physical CPU cores.

Rust accommodates Futures without additional runtime overhead (unlike “green threads”).

WASM

For hand-written Rust, JavaScript and HTML, consider starting with bare metal WASM rather than messing with the entire tooling of wasm-pack, wasm-bindgen, webpack and npm to produce a Rust-powered webpage every time.

WebAssembly:

For building webapps, start with rust-webpack-template.

For building libraries, start with wasm-pack-template.

Alternatively, MiniWASM is “a minimalist Rust WebAssembly project template” that was created for “projects that have more strict performance requirements” than wasm-bindgen.

Tooling, Runtimes & Edge Computing:

Also:

Web Dev

Data Modeling

Data Storage

Interacting With Other Languages

Rust calling other languages:

Rust embedded into other languages:

Rust calling into the Dalvik / JVM:

Robustness

Ensure cancel-safety where appropriate.

Essentially, avoid losing data that has already been queued which also applies to Mutex.

This is an advanced topic; however:

Essentially, migrate away from queue.push(foo).await to quque.reserve().await.push(foo) but also understand why.

See tokio’s reserve().

See also just this one small section, and optionally read the whole article if thirsty for more: async fn is an inversion of control

Embedded Systems

Advocacy & Comparisons

A survey of programming languages illustrates that each serves different purposes: https://stackshare.io/stackups/python-vs-ruby-vs-rust

Code Editors

Rust-stable includes rust-analyzer, an implementation of Language Server Protocol (LSP).

Configure Emacs for Rust

See Emacs section within rust-analyzer manual.

Also consider:

Visual Studio Code

For non-Emacs heathens out there…

RLS

Rust-stable includes rust-analyzer which supersedes rls.

From the official websites and repos:

Search packages, and read their documentation:

Forum, IRC Channels and more are linked from Community page.

Academic Publications:

Helpful For Understanding

In no particular order:

Runtime Profiling

Error-Handling

As of late 2022, a bit of consensus pointed to simply using:

Older articles:

Interesting Libraries, Frameworks & Packages

Interesting Tools Made With Rust

See also:

Plucked from the ‘net, most are offered without context or explanation but probably seen on This Week in Rust. Newer items are usually added to the bottom of this list unless releavant as bullet point under an existing item.

(Tokio related links have been relocated to their own section above.)

See Also

Maintainer Notes

This page is a perpetual work-in-progress.

It should have begun life within a code repo, but this is what we have…

Most updates here since 2018 were gleaned from This Week In Rust. Other content since 2015 came from the various lists and fora mentioned in Stay Current above.

Copyright © 2023 Daniel Joseph Pezely
May be licensed via Creative Commons Attribution.