Quick notes, half-formed ideas, and learning snippets. Mostly unpolished thoughts about coding, languages, and concepts I'm exploring.
January 15, 2025
RustOwnership
Diving into Rust’s ownership model today. The borrow checker is some combination of frustrating and brilliant. Realized that most of my mental model from C++ doesn’t quite map over - Rust’s approach is more about preventing problems at compile time rather than managing them at runtime.
Still wrapping my head around lifetimes. The syntax feels verbose but I suspect it’ll click once I write enough code. For now:
Key Learnings
Ownership rules: each value has one owner, ownership can be moved
Borrowing: references allow temporary access without taking ownership
Example Code
// This works - ownership is movedlets1=String::from("hello");lets2=s1;// s1 is no longer valid here// This works - borrowinglets1=String::from("hello");letlen=calculate_length(&s1);// s1 still validprintln!("{}",s1);fncalculate_length(s:&String)->usize{s.len()}
The compiler errors are actually helpful once you understand what they’re telling you. Much better than segfaults at runtime!