Return types
Functions declare their return type:
fn greet(name: &str) -> String {
format!("Hello, {name}")
}
String is the owned string type. format! builds it from a template. Functions return () when they produce no value.
Closures
Closures capture their environment:
let multiplier = 10;
let f = |x| x * multiplier; // captures multiplier
Closures can capture variables by reference, mutable reference, or by ownership. Rust picks the least restrictive capture automatically.