Est. read time: 3 minutes | Last updated: July 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 Tools

  • 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

Compilation

  • If 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.

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).

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

Async

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

References

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

To Read

Books

Repos