Chapters: Ch 1 · Ch 2 · Ch 3 · Ch 4 · Ch 5
Rust
Rust Design Patterns (rust-unofficial.github.io) Community-maintained book of idiomatic Rust patterns: RAII guards, type state machines, builder pattern, newtype wrappers, and anti-patterns to avoid. Essential reference for writing Rust code that leverages the borrow checker’s guarantees rather than fighting them. https://rust-unofficial.github.io/patterns/
Rust Cheat Sheet Quick-reference guide to Rust syntax: lifetimes, trait bounds, closures, iterators, pattern matching, and common standard library APIs. Useful as a desktop companion for developers who know Rust but need to recall specific syntax during coding sessions. https://upsuper.github.io/rust-cheatsheet/
Type-Level Programming in Rust (Will Crichton) Will Crichton’s guide to expressing invariants and constraints in Rust’s type system: phantom data, zero-sized types, associated types, and const generics for encoding state machines and API contracts at compile time rather than at runtime. https://willcrichton.net/rust-api-type-patterns/
graydon2: Notes on Rust, Mutable Aliasing, and Formal Verification Graydon Hoare’s — Rust’s original creator — blog on the relationship between Rust’s aliasing rules and formal verification: how the borrow checker’s guarantees enable both safe concurrency and machine-checkable correctness proofs. https://graydon2.dreamwidth.org/
Rust Formal Verification (xav.io) Resource on formally verifying Rust programs using tools like Kani, Creusot, and Prusti — leveraging Rust’s ownership model to make verification tractable. An active research area connecting Rust’s type system to formal methods. https://xav.io/
100 Exercises To Learn Rust (rust-exercises.com) Structured curriculum of 100 progressive Rust exercises, starting from basic types and ownership through iterators, traits, and error handling. Particularly effective because it provides a compiler-driven feedback loop — exercises only pass when the Rust code is correct. https://rust-exercises.com/02_basic_calculator/00_intro
Rust Atomics and Locks — Mara Bos Comprehensive book on low-level concurrent programming in Rust: memory ordering, atomic operations, spinlocks, mutexes, and condition variables implemented from first principles. Required reading for systems programmers building lock-free data structures in Rust. https://marabos.nl/atomics/
Implementing Git from Scratch in Rust (Jon Gjengset, YouTube) Jon Gjengset’s extended live-coding session implementing a significant portion of git in Rust, demonstrating how to apply Rust idioms to a real-world systems project: object storage, pack files, delta compression, and the ref system. https://www.youtube.com/watch?v=u0VotuGzD_w
Golem’s Rust Transaction API (blog.vigoo.dev) Daniel Vigovszky’s blog on building a transactional API in Rust for the Golem platform — a distributed computing runtime. Covers how Rust’s ownership model interacts with distributed system guarantees and durable execution primitives. https://blog.vigoo.dev/
LogLog Games: Leaving Rust Gamedev LogLog Games’ post-mortem on choosing to leave Rust for game development: the cognitive overhead of the borrow checker in game entity system patterns, compile times, and the ergonomic friction of dynamic dispatch in performance-critical game loops. A balanced critique from practitioners. https://loglog.games/blog/leaving-rust-gamedev/
Google Hails Move to Rust for Drop in Memory Vulnerabilities Google’s report on the measurable security improvement from migrating Android and other components from C++ to Rust: memory safety vulnerabilities in migrated code dropped to near zero, validating Rust’s ownership model as a practical security engineering tool. https://www.yahoo.com/tech/google-hails-move-rust-huge-180100292.html
Introducing Distill CLI — Rust-Powered Media Summarization (allthingsdistributed.com) Werner Vogels (AWS CTO) introduces Distill CLI — an efficient Rust tool for summarizing media files using LLMs — with a code review story about learning Rust from Amazon Rustaceans. A pragmatic example of Rust adoption for performance-sensitive CLI tooling. https://www.allthingsdistributed.com/2024/06/introducing-distill-cli.html
Hands-On Data Structures and Algorithms With Rust (San Mateo County Libraries) Library record for a book implementing classic data structures and algorithms in Rust: trees, graphs, sorting, and dynamic programming. Bridges algorithmic fundamentals with Rust-specific ownership patterns. https://smcl.bibliocommons.com/v2/record/S76C3254158
Breaking Out of the Fold (Ethan Kent’s Dev Blog) Essay on the problem of early termination within fold/reduce operations in functional languages: the challenge of short-circuiting without exceptions, using techniques like returning early via Option, Either, or lazy evaluation. Examines how different languages handle this. https://ethankent.dev/posts/breaking_fold/
Rust LeetCode Solutions (Knight’s Tour)
Rust: Check Valid Grid (Knight’s Tour Validation) Rust implementation of LeetCode’s knight’s tour grid validation problem, using fold for traversal and custom Move/Rc structs for position tracking. The optimized version eliminates the visited array by leveraging the grid’s value sequence as implicit state.
impl Solution {
pub fn check_valid_grid(grid: Vec<Vec<i32>>) -> bool {
#[derive(Copy, Clone)]
struct Move{row: isize, col: isize}
#[derive(Copy, Clone)]
struct Rc{row: usize, col: usize}
fn mv(row: isize, col: isize) -> Move {
Move{row: row, col:col}
}
fn check_init(grid: &Vec<Vec<i32>>) -> bool {
(grid.len() > 0) && (grid[0].len() > 0) && (grid[0][0] == 0)
}
fn get_next(grid: &Vec<Vec<i32>>, curr : Rc, n: isize) -> Option<Rc> {
let moves: Vec<Move> = vec!(mv(-2, -1), mv(-2, 1), mv(-1, -2), mv(-1, 2 ), mv(1, 2), mv(1, -2), mv(2, 1), mv(2, -1));
let knight_step = grid[curr.row][curr.col];
moves.iter().fold(None, |next_pos_o, m| {
let r = m.row + curr.row as isize;
let c = m.col + curr.col as isize;
next_pos_o.or_else(|| {
if ((r >= 0) && (r < n) && (c >= 0) && (c < n) &&
(grid[r as usize][c as usize] == knight_step + 1)) {
Some(Rc{row:r as usize, col:c as usize})
} else {
None
}})
})
}
fn check_tour(grid: &Vec<Vec<i32>>) -> bool {
let n = grid.len() as isize;
let mut curr = Rc{row: 0, col: 0};
let mut next_o = get_next(grid, curr, n);
while (next_o.is_some()) {
curr = next_o.map_or_else(|| curr, |n| n);
next_o = get_next(grid, Rc{row: curr.row, col: curr.col}, n);
}
grid[curr.row][curr.col] == ((n*n - 1) as i32)
}
check_init(&grid) && check_tour(&grid)
}
}
Runtime 710ms Beats 100.00%
Scala LeetCode Solutions
Knight’s Tour Validation (Scala)
Scala: Check Valid Grid — Version 1 and Version 2 Two Scala implementations of the knight’s tour grid validation problem: Version 1 uses an explicit visited buffer (774ms, 50th percentile); Version 2 eliminates the visited set by relying on monotonically increasing step values in the grid (710ms, 100th percentile). The optimization illustrates how understanding problem constraints eliminates unnecessary bookkeeping. Submitted as “kodebale” at Sep 25, 2024
Version 1 (with visited tracking, 774ms Beats 50%):
object Solution {
case class Rc (row:Int, col:Int)
def checkValidGrid(grid: Array[Array[Int]]): Boolean = {
val n = grid.size
def checkInit():Boolean = (n > 0) && (grid(0)(0) == 0)
val visited = scala.collection.mutable.ArrayBuffer.empty[Rc]
def getNextRc(currRc:Rc):Option[Rc] = {
val nrInc = Array(-2, -2, -1, -1, 1, 1, 2, 2)
val ncInc = Array(-1, 1, -2, 2, 2, -2, 1, -1)
val knightStep = grid(currRc.row)(currRc.col)
visited += currRc
val nextPoss:Array[Rc] = (0 until 8).toArray.flatMap(i => {
val nr = currRc.row + nrInc(i)
val nc = currRc.col + ncInc(i)
val nrc = Rc(nr, nc)
if ((nr >= 0) && (nr < n) && (nc >= 0) && (nc < n) && (visited.find(rc => nrc == rc).isEmpty)) {
Array(nrc)
}
else {
Array[Rc]()
}
})
nextPoss.find(rc => grid(rc.row)(rc.col) == knightStep + 1)
}
def checkTour() : Boolean = {
var currO:Option[Rc] = Some(Rc(0,0))
var nextO = getNextRc(Rc(0,0))
while(nextO.isDefined) {
currO = nextO
nextO = getNextRc(nextO.get)
}
val finalrc = currO.getOrElse(Rc(0,0))
grid(finalrc.row)(finalrc.col) == (n*n)-1
}
checkInit() && checkTour()
}
}
Version 2 (optimized, 710ms Beats 100%):
object Solution {
case class Rc (row:Int, col:Int)
def checkValidGrid(grid: Array[Array[Int]]): Boolean = {
val n = grid.size
def checkInit():Boolean = (n > 0) && (grid(0)(0) == 0)
def getNextRc(currRc:Rc):Option[Rc] = {
val nrInc = Array(-2, -2, -1, -1, 1, 1, 2, 2)
val ncInc = Array(-1, 1, -2, 2, 2, -2, 1, -1)
val knightStep = grid(currRc.row)(currRc.col)
val nextPoss:Array[Rc] = (0 until 8).toArray.flatMap(i => {
val nr = currRc.row + nrInc(i)
val nc = currRc.col + ncInc(i)
val nrc = Rc(nr, nc)
if ((nr >= 0) && (nr < n) &&
(nc >= 0) && (nc < n) &&
(grid(nrc.row)(nrc.col) == knightStep + 1)) {
Array(nrc)
}
else {
Array[Rc]()
}
})
nextPoss.find(rc => grid(rc.row)(rc.col) == knightStep + 1)
}
def checkTour() : Boolean = {
var currO:Option[Rc] = Some(Rc(0,0))
var nextO = getNextRc(Rc(0,0))
while(nextO.isDefined) {
currO = nextO
nextO = getNextRc(nextO.get)
}
val finalrc = currO.getOrElse(Rc(0,0))
grid(finalrc.row)(finalrc.col) == (n*n)-1
}
checkInit() && checkTour()
}
}