Rust shifts work to compile time (static analysis, monomorphization) to guarantee safety and performance at runtime, eliminating the need for a garbage collector or runtime checks for memory safety. The compiler enforces ownership and borrowing rules before the program runs, trading longer build times for faster, safer execution.
// Compile-time: The compiler checks ownership rules here.
// Runtime: No overhead for garbage collection or bounds checking on safe code.
fn main() {
let s = String::from("hello");
let r = &s; // Compiler ensures 's' lives long enough for 'r'
println!("{r}");
}