Table of Contents
Features:
- Compiled to machine code
- Strong, static typing
- Imperative, with functional aspects
- Can do both high-level and low-level programming
- No garbage collection or runtime
- Control allocation
- Safe (e.g. no null pointers, correct concurrency...)
- Cross-compilation (WebAssembly!)
- Works with traditional tools (e.g.
perf
,gdb
,valgrind
...) - Modern type system
- Long-term viability: Mozilla, Dropbox, CloudFlare, Microsoft, Google, Amazon, Facebook, Atlassian, npm
Drawbacks:
- Learning curve: borrow checker
- Ecosystem: still growing
- Compile times are great compared to Haskell, but still slow compared to Go, C.
- Vendor support (e.g. CUDA sdk, NVIDIA sdk), no C++ integration.
- Windows ? Linux and MacOS mainly
- Declarative macros e.g.
vec!
- Procedural macros e.g.
#[derive(MyTrait)]
- Example
Resources:
A common practice is to use trait
s and parametric struct
s.
Use mockall for testing.
- Algebraic Data Types + patterns
- Efficient Generics (monomorphization)
- Higher-order functions
- Iterators
Option(Maybe)
andResult(Either)
- No Monads, but we have
?
- sequence and traverse
Not recommended:
- frunk: HList, Generic, Semigroup, Monoid ...
- fp-core.rs
Rust is sold (or was sold) as an embedded programming language.
Lots of tools:
See example
Rust can cross-compile to a big number of platforms: x86, arm, mips, powerpc, risc-v... with just cargo build --target=x86_64-apple-darwin
- Recommended package layout
- Explore nom
rustc
cargo
rustfmt
clippy
- Any toolchain(channel + version), any target(cross-compilation), any component(clippy, lsp)!
rustup run stable rustc --version
(orrustc +stable --version
)rustup default nightly
rustup component add rust-docs
- rust-analyzer:
rustup +nightly component add rust-analyzer-preview
- Vscode, vim/neovim, emacs, etc.
- std
- crates.io e.g. https://crates.io/crates/tokio
- Docs.rs e.g. https://docs.rs/tokio/latest/tokio/
- rustodc
- https://lib.rs : I don't find it super useful
- https://github.com/rust-unofficial/awesome-rust
- https://github.com/vaaaaanquish/Awesome-Rust-MachineLearning
- https://cryptography.rs/
Example: picking an HTTP Server
Candidates:
- https://github.com/SergioBenitez/Rocket (18k stars)
- https://github.com/actix/actix-web (15k stars)
- https://github.com/seanmonstar/warp (7k stars)
- https://github.com/tokio-rs/axum (6k stars)
Start with The Rust Book and see the other resources below.