What is Rust Max?
Rust Max,
also known by its crate name rmx
,
is a collection of crates, tools, and documentation
for the Rust programming language.
Rust is a modern systems programming language that is extremely fast and does not crash. It is suitable for development of high-performance, low-level software as in operating systems, databases, and distributed systems; as well as cli, web, device, and application development.
Rust Max is a comprehensive guide to the Rust ecosystem
for new and old Rust programmers,
including a "batteries-included" supercrate
of selected high-quality Rust libraries:
rmx
.
Rust Max is not an official Rust project.
Rust mastery awaits
- Step 1: Install Rust with
rustup
. - Step 2: Learn Rust from The Rust Max Library.
- Step 3: Build programs with Rust crates.
- Step 4: Maintain programs with Rust tools.
Rust Max addons
todo
Easy Mode Rust
Starting a project
Updating dependencies in lockfile
cargo update
Updating dependencies in Cargo.toml
cargo upgrade
With no extra arguments cargo upgrade
modifies
Cargo.toml
files such that the dependencies are
set to their latest compatible versions.
In this way it similar to cargo update
but for manifests
instead of lockfiles.
todo This command is from the cargo-edit
package.
Upgrading dependencies across minor versions in Cargo.toml
cargo upgrade --incompatible
topics
- anyhow, thiserror
rustup
Installation
Rust is installed with the rustup
tool.
Linux, Mac OS, and Unixes
run the following in your shell then follow the onscreen instructions:
curl -sSf https://sh.rustup.rs | sh
Windows for 64-bit x86_64
download and run rustupβinit.exe then follow the onscreen instructions.
Windows for 32-bit i686
download and run rustupβinit.exe then follow the onscreen instructions.
Rust Max: Crates
Rust Max: Tools
- Standard Rust tools:
cargo
rustc
rustup
rustdoc
rustfmt
clippy
just
mdbook
bindgen
miri
- Cargo plugins:
cargo-edit
cargo-clean-all
cargo-deny
cargo-license
cargo-audit
cargo-generate
- More Rust tools:
clippy-control
- Non-Rust tools for Rust:
mold
- More general developer tools:
ripgrep
tokei
basic-http-server
gist
jaq
jsonxf
fd
sd
dust
todo say something here
Standard Rust tools
π cargo
The Rust build and packaging tool.
It is the central tool in most Rust development workflows.
It is part of every Rust toolchain,
usually managed by rustup
.
ποΈ The
cargo
Book
π rustc
π rustup
π rustfmt
π mdbook
π bindgen
π miri
Cargo plugins
π cargo-edit
Extra cargo
subcommands for editing Cargo.toml
.
cargo install cargo-edit
π
crates.io
Page
ποΈ Source Repository
Installing cargo-edit
provides two cargo
subcommands:
cargo add
was once provided by cargo-edit
but since Rust 1.62.0
is built into cargo
itself.
π cargo-clean-all
π cargo-deny
π cargo-license
π cargo-audit
π cargo-generate
More Rust tools
π clippy-control
Non-Rust tools for Rust
π mold
A high-performance linker that significantly speeds up Rust builds on Linux.
rustmax install-tool mold
ποΈ Source Repository
Linking is one of the most time-consuming stages of a Rust build,
and it has to be redone every time you test your program.
On Linux the mold
linker is faster than the default linker.
Setting up mold
manually requires configuring .cargo/config.toml
and ensuring the linker is properly installed,
but the Rust Max CLI tool handles this setup automatically.
More general developer tools
π ripgrep
π just
A simple and suprisingly useful command runner with make
-like syntax.
cargo install just
π
crates.io
Page
ποΈ Source Repository
Almost every project has a handful of commands the developer(s)
uses frequently. Put these in a justfile
so the menu of
commands for this project is always obvious, which
can be extra helpful after years away from a project.
just
runs commands listed in a file named justfile
.
The justfile
lives your project's root directory,
and is configured with a make
-like syntax:
default:
just --list
install-tools:
cargo install mdbook
cargo install mdbook-yapp
clean: doc-clean
cargo clean
doc-clean:
rm -rf out
It's a simple idea, but suprisingly useful. And don't worry that it looks like
a Makefile
β it is much more fun and sensible in use than make
.
When you come back to a project and see there's a justfile you
know to run just --list
and you'll immediately see what
was on the previous maintainer's mind.
$ just --list
Available recipes:
build
check
clean
default
doc-book
doc-build
doc-clean
doc-crates
install-tools
lint
maint-audit
maint-duplicates
maint-lock-minimum-versions # useful prior to running `cargo audit`
maint-outdated
maint-upgrade
prebuild
publish
publish-dry
replace-version old new
test
test-min-version-build
$ just build
Compiling rustmax-cli v0.0.5 (β¦/rustmax/crates/rustmax-cli)
β¦
π tokei
π basic-http-server
π gist
π jaq
π jsonxf
π fd
π sd
π dust
The Rust Max Library
The Rust language and its ecosystem is documented in "books"
(rendered with mdbook
), and most of these links are to books.
Links with a bookmark icon, π, are to particularly notable or useful chapters within a book.
The Rust language
- The Rust Programming Language (The Book)
- Rust By Example
- The Rust Reference
- π Conditional compilation. Including which cfgs are set by rustc.
- π Behavior considered undefined
- The Rustonomicon
- The Rust Edition Guide
- The Little Book of Rust Macros
- Rust API Guidelines
- Rust Unsafe Code Guidelines
- Rust Error Codes Index
- The Rust Unstable Book
- The Rust Style Guide
- Rust Release Notes
The Rust standard library
std
- π
std::collections
- π
std::error
- π
std::ptr
. Safety, undefined behavior, and "provenance". - π
std::sync
- π
std::sync::atomic
- π
core
alloc
proc_macro
Standard Rust tools
- The
cargo
Book- π The manifest format
- π Environment variables that affect the Cargo build process.
- π Configuration format. Cargo has many interesting configuration options.
- The
rustc
Book - The
rustup
Book - The
rustdoc
Book - rustfmt (todo)
- The
clippy
Book - The
just
Programmer's Manual - The
mdbook
Book - The
bindgen
User Guide - miri (todo)
The Rust crate ecosystem
Domain-specific Rust
The Rust Project internals
- Rust Project Goals
- Guide to
rustc
Development - Standard Library Developers Guide
- Rust Forge
- Rust RFCs
The Rust Max CLI
To install:
cargo install rustmax-cli --locked
The Rust Max CLI provides a number of small tools that help manage a Rust development environment, Rust tools, and Rust projects.
- Print Rust sytem status
- Install the
mold
linker - Install all Rust Max tools
- Create a Rust Max project from template
- Build the Rust Max documentation
- Run all lint-style checks
- Emit opinionated
rustfmt.toml
- Emit opinionated
deny.toml
- Emit opinionated
clippy-control.toml
Print Rust system status
Rust Max understands your rustup toolchain status,
Rust Max tools installed via cargo,
and other tools like the mold
linker.
$ rustmax status
... todo ...
Set up the mold
linker
Linking is one of the most time-consuming stages of a Rust build, and it has to be redone every time you test your program.
On Linux the mold
linker is faster than
the the default linker.
Setting it up manually is not difficult,
but just hard enough that I have to look it up
every time.
The Rust Max CLI tool can do it instead:
rustmax install-tool mold
Use rustfmt::skip
Sometimes exact formatting is important to make code beautiful.
Don't be afraid annotate with #[rustfmt::skip]
.
Use Option
with ?
The ?
operator works with Option
to early-return on None
,
making option-heavy code much cleaner.
#![allow(unused)] fn main() { fn find_user_email(id: u32) -> Option<String> { let user = database.find_user(id)?; // Return None if user not found let profile = user.get_profile()?; // Return None if no profile let email = profile.email?; // Return None if no email Some(email) } }
An alternative to match
or if let
statements, ?
lets you chain
operations that might fail, automatically propagating None
up the call stack.
Put common development commands in a justfile
Almost every project has a handful of commands the developer(s)
uses frequently. Put these in a justfile
so the menu of
commands for this project is always obvious, which
can be extra helpful after years away from a project.
just
runs commands listed in a file named justfile
.
The justfile
lives your project's root directory,
and is configured with a make
-like syntax:
default:
just --list
install-tools:
cargo install mdbook
cargo install mdbook-yapp
clean: doc-clean
cargo clean
doc-clean:
rm -rf out
It's a simple idea, but suprisingly useful. And don't worry that it looks like
a Makefile
β it is much more fun and sensible in use than make
.
When you come back to a project and see there's a justfile you
know to run just --list
and you'll immediately see what
was on the previous maintainer's mind.
$ just --list
Available recipes:
build
check
clean
default
doc-book
doc-build
doc-clean
doc-crates
install-tools
lint
maint-audit
maint-duplicates
maint-lock-minimum-versions # useful prior to running `cargo audit`
maint-outdated
maint-upgrade
prebuild
publish
publish-dry
replace-version old new
test
test-min-version-build
The Rust Standard Library Revisited
The Rust Standard Library contains many important tools. Much of its documentation is excellent, but some, including the Tour of the Rust Standard Library, has bitrotted.
API docs
Rust standard library classics
Some of the Rust standard library documentation is excellent, with good overviews of systems programming topics generally.
- π
std::collections
- π
std::error
- π
std::sync
- π
std::sync::atomic
A (New) Tour of the Rust standard library
todo
The Rust Ecosystem
Rust resources
Error handling - anyhow
and thiserror
Serialization - serde
Command line handling - clap
Derive all the things
Logging - log
and env_logger
crate::env_logger::Builder::new()
.filter_level(log::LevelFilter::Info)
.parse_default_env()
.init();
Async I/O - tokio
Managing Rust toolchains
Procedural macros
Rust build scripts
todo topics
cargo add
cargo update
cargo upgrade
- lockfiles
How Do I β¦ in Rust?
Discovery
β¦ find a crate for a given purpose?
β¦ find the latest version of a crate?
Project organization
β¦ organize a Rust workspace?
Conveniences
β¦ define "extension" methods on a type in another crate?
β¦ guarantee a trait is object-safe?
static_assertions::assert_obj_safe!(MyTrait);
Error handling and debugging
β¦ handle errors simply and correctly?
β¦ structure errors in a public API?
β¦ set up basic logging?
Collections
β¦ create a fast HashMap
?
β¦ convert from slices to fixed-length arrays?
Numerics
β¦ convert between numeric types ideomatically?
β¦ perform math ideomatically?
β¦ convert between ints and bytes?
Encoding, serialization, parsing
β¦ serialize to and from JSON?
β¦ decide what format to use with serde
?
Time
β¦ parse and render standard time formats?
Random numbers
β¦ generate a strong random number?
β¦ generate a strong random number from a seed?
β¦ generate a fast random number from a seed?
Cryptography
β¦ calculate a cryptographic content hash?
Parallelism and Concurrency
β¦ initialize a global value?
todo LazyLock
, OnceLock
, and Once
.
β¦ send messages to/from async code?
todo futures::channels
Asynchronous I/O
β¦ set up the tokio
event loop?
β¦ stub an unwritten async fn
?
Networking and web
β¦ make a synchronous HTTP request?
β¦ configure a basic HTTP server?
Text / unicode
Terminal / CLI
β¦ set up a simple CLI parser with subcommands?
β¦ display colors in the terminal?
β¦ read line-based input from the terminal?
System / OS
β¦ read environment variables?
β¦ work with a temporary file?
β¦ work with multiple files in a temporary directory?
Testing
β¦ create a custom test harness?
β¦ create a custom table-based test harness?
Build scripts
β¦ write build scripts ideomatically?
β¦ link to a native static library?
β¦ compile and link a C source file?
FFI / interop
β¦ create Rust bindings to a C/C++ program?
Procedural macros
let else
topics
- justfiles
- time - jiff vs chrono vs time
- xtask and xshell
- project organization
- extension_trait
- global initialization - lazy_static vs once_cell vs std
- lazy_static -> LazyLock
- lazy_static can be used with a spin lock
- OnceLock is in std
- error handling
- ideomatic casting
- ideomatic math
The Rust Max Radar
This is where we collect crates and tools of interest, but that are not yet part of Rust Max.
Crates
backtrace-on-stack-overflow
. Nice missing feature, but code looks underdeveloped.bitvec
. Operate directly on bits.boringtun
. WireGuard.comrak
. Markdown parser.console
,dialoguer
, andindicatif
. Pretty terminals.criterion
. Advanced benchmarking.dashmap
. Concurrent hash map.datatest-stable
Data-driven tests.dotenv
.derive-new
Derive thenew
function.ena
. The union find algorithm.encoding
,charset
,codepage
,oem_cp
,icu_normalizer
,detone
. Text encoding.enum-iterator
. Iterate over variants.eyre
. Sophisticated error handling.flate2
.fnv
or some other non-ahash fast hashhashbrown
. Hash maps with no-std.home
ignore
. Likewalkdir
but obeys.gitignore
.include_dir
.indexmap
libm
. Useful for no-std.memchr
memmap
ndarray
nix
notify
. File system notification.num
.num-traits
ordered-float
parking_lot
Non-poisoning mutexes, etc.petgraph
ratatui
. Seriously cool CLIs.rangetools
rustls
. TLS.rustversion
rust-embed
. Embedding of file system resources into binaries, with hot-reloading during development.scopeguard
. Likedefer
.smallvec
. The "small vector" optimization. There may be better / newer options.sqlx
.tar
.tungstenite
. WebSockets.stacker
. Manually-growable call stacks.time
. Another time crate.tracing
.tracing-subscriber
.tracing-tracy
.unicode-xid
.xdg
Tools
Wanted
- SHA3
- gRPC
- wasm crates and tools, wasm-bindgen, stdweb
- threadpool
- zip, gzip
- parser generator (pest?)
- alternative to bitflags
- gui stuff
- winit, wgpu vs glow, morphorm, css, iced vs egui
- i18n
- QUIC - either quinn or quiche
- HTTP3
- markdown
- csv
- small string, smartstring
- rational numbers
- fixed-point, decimal numbers, rust-decimal
Replacements
- num_cpu -> std::thread::available_parallelism
Graveyard
These projects were once useful or notable, but are now deprecated by others.
lazy_static
. Usestd::sync::LazyLock
.once_cell
. Usestd::sync::OnceLock
.
External Rust Resources
These are not part of Rust Max.
Must know URLS π€―
Tier 1 - looks good π
- Rust Language Cheat Sheet. This looks awesome.
- Rust Component History.
rustup
toolchain status. Look here to figure out if your nightly toolchain had component build failures. - The Little Book of Rust Books
- "Can I Use _?"
Tier 2 - unvetted π
- Rust String Conversions Cheat Sheet
- Rust Iterator Cheat Sheet
- Rust Container Cheet Sheet
- Lib.rs
- Secure Rust Guidelines.
- List of security-related projects
- Tour of Rust's standard library traits
- Another Container Cheet Sheet
todo
- rust-lang.org
- play.rust-lang.org
- rustup.org
- crates.io
- std.rs
- docs.rs
- query.rs
- social and forums
- releases.rs