08
Languages / Intermediate
Rust and systems programming
Ownership, borrowing, Result/Option, Cargo, concurrency, and when Rust is useful in desktop or systems tools.
01Ownership model
Rust uses ownership and borrowing to prevent many memory-safety bugs at compile time. A value has an owner; references borrow access; lifetimes describe how long references may remain valid.
rustBorrow a slice instead of taking ownership
fn total(values: &[i32]) -> i32 {
values.iter().sum()
}
fn main() {
let values = vec![10, 20, 30];
println!("{}", total(&values));
}
02Explicit errors
rustResult-based failure
use std::fs;
fn load_config(path: &str) -> Result<String, std::io::Error> {
fs::read_to_string(path)
}
03Cargo workflow
bashQuality gates
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test
cargo build --release