Introduction to Rust
January 07, 2023
Rust is a fast, safe, and concurrent systems programming language that is quickly gaining popularity in the high frequency trading (HFT) community.
Rust is a systems programming language that was designed to be fast, safe, multi-threaded and concurrent. In addition, it has a unique ownership and borrowing system that allows for efficient memory management without needing a garbage collector, which can reduce latencies and improve performance.
I've been using Rust for a while now (2018), and I find it to be a great language applications that require high performance and low latency. It works well with other languages too, such as Python via PyO3, which means you can write performance-critical parts of your application in Rust and expose them to Python for quick research/prototyping.
Quick setup
- Install rust
- Check version
rustc --version
- To show active/installed toolchains
rustup show
- To update rust nightly toolchain run
rustup update nightly
- To update rust stable toolchain run
rustup update stable
- To change the default toolchain to nightly
rustup default nightly
- To install specific nightly toolchains
rustup toolchain install nightly-2023-01-07
- Update dependencies in a package
cargo update
Useful dev packages
To install globally via
cargo install <package>
- cargo-edit to add
cargo-add
,cargo-rm
,cargo-upgrade
commands - cargo-watch to watch for changes and reload during development
- cargo-expand for macro expansion.
- cargo-show-asm - cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code
References
Here are a few references for Rust programming:
- Rust lang - entry point to rust language
- Rust book - how rust works and its paradigms
- Rust source code - hosted on github
- Rust reference - for the syntax
- Rust std - standard library documentation
- Rust design patterns - design patterns, anti-patterns and idioms
- Awesome Rust - a curated list of Rust code and resources
- Scientific computing - collections of crates for scientific computing
- Rust Atomics and Locks by Mara Bos