Est. read time: 4 minutes | Last updated: December 17, 2024 by John Gentile


Contents

Why Rust?

Rust is relatively young compared to other systems programming languages. However, it has taken many of the lessons learned from decades of other languages to form something that:

  • Puts memory safety at the forefront
  • Allows for similar speed and zero-cost abstractions as C++

Why Not Rust?

Ignoring criticisms based on feelings and/or fanboy-isms, there has been some valid and well-researched opinions on where Rust may still fall short:

Install and Getting Started

  • Installing Rust is fairly simple using the rustup script: $ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
    • On macOS, make sure C compiler is installed with $ xcode-select --install
  • Rust can be updated at any time with $ rustup update

Getting Started Resources

Books

Tools

Cargo

cargo is installed automatically with the typical install process.

  • A new Rust project can be created by running $ cargo new <project_name> and, by default, creates a variety of helpful files:
    • Creates a .gitignore file and -if not already within a git repo- initializes a new Git repo
      • To not have a Git repo instantiated, pass --vcs none.
    • A TOML config file Cargo.toml that describes the metadata and dependencies of the Rust project.
    • A src/ directory in which Rust source should live.
    • Add --lib to the end of cargo new to create a library (no binary compilation target).
  • When using a Cargo project, $ cargo build can be used
    • $ cargo run can be used to build and then execute in one command.
    • Or for a more straight forward approach, $ rustc main.rs compiles the Rust file main.rs into an executable file main.

For more info, see The Cargo Book.

As part of cargo there’s also:

  • clippy: a collection of lints to catch common mistakes and improve Rust code
  • rustfmt: a Rust code formatter, can also be run with cargo fmt.

rustdoc

Rust ships with a tool called rustdoc which can generate documentation by parsing specially formatted comments in Rust source code.

rustdoc can also perform documentation tests within comments.

Cross-Compile & FFI

Other Tools

  • rust-analyzer: implements Language Server Protocol (LSP) for Rust (allows IDEs/editors to have completion, definition, goto, etc. features).
  • cargo-audit: audits dependencies for crates with known security vulnerabilities, maintained by RustSec Advisory Database.
  • grcov: collect & aggregate code coverage data for source files (also supports C/C++ projects, or files that can be processed by llvm/clang/gcc).
  • loom: concurrency permutation testing for parallel Rust code.
  • Miri: interpreter for Rust’s mid-level interpreter (MIR) and detect classes of undefined behavior.

Language

Macros

Async

See rust-async-framework for more details and implementation examples.

References

Rust for Performance

Low-Level / Embedded

Rust for Linux Kernel Development

References

NOTE: offline documentation is locally installed with rustup and can be opened in your browser by simply running rustup doc. For public/open-source crates, documentation is also often found in Docs.rs.

Rust Core Docs

Application Domain Docs and Repos

General Repos

Some repos that are useful in general Rust programs, or as reference for good Rust practices:

  • rust-unofficial/awesome-rust: collection of neat Rust repos and material
  • BurntSushi/ripgrep: very fast grep replacement, with great reference Rust codebase.
  • alacritty: cross-platform, OpenGL terminal emulator.
  • awslabs/mountpoint-s3: A simple, high-throughput file client for mounting an Amazon S3 bucket as a local file system.
  • hashbrown: a Rust port of Google’s high-performance SwissTable hash map, adapted to make it a drop-in replacement for Rust’s standard HashMap and HashSet types.
  • tracing: a framework for instrumenting Rust programs to collect structured, event-based diagnostic information.