Rust ensures memory safety without a garbage collector. It achieves this through a system of ownership with a set of rules that the compiler checks at compile time.
Here is a classic example of ownership in action:
fn main() {
let s1 = String::from("hello");
let s2 = s1;
// println!("{}, world!", s1); // This would verify error!
println!("{}, world!", s2);
}
We can also use inline code like let mut x = 5; to denote variables within our prose.