A hands-on Rust learning project exploring core language concepts through annotated code examples.
Located in src/ownership/study.rs.
- Stack vs Heap — fixed-size data lives on the stack; dynamically sized data lives on the heap and is accessed via pointers.
- Move vs Copy — assigning a heap-allocated value (e.g.
String) moves ownership; primitive types (e.g.i32) are copied. - Borrowing — use
&variableto pass a reference without transferring ownership (immutable by default). - Mutable references — use
&mut variableto allow mutation; only one mutable reference to a value is allowed at a time (prevents data races). - Reference rules — you can have multiple immutable references OR one mutable reference, but not both simultaneously.
- Dangling references — Rust's compiler prevents returning references to values that have been dropped.
- Slice type — a reference to a contiguous sequence of elements in a collection; holds no ownership.
src/
main.rs # Entry point
ownership/
study.rs # Ownership, borrowing, and slice concepts
cargo runInstall cargo-watch:
cargo install cargo-watchStart modules
# ownership
cargo watch -w src -x "test ownership"
# pattern matching
cargo watch -w src -x "test pattern_matching"
# functional programming
cargo watch -w src -x "test functional_programming -- --nocapture"