Lifetimes: Surviving the First Encounter
Day 32, and today we are stepping into one of Rust’s most talked-about features. If you have heard scary stories about lifetimes, do not worry. This is your first encounter, and we are going to make it approachable.
If you are coming from C#, the idea of lifetimes might feel strange at first. In .NET you lean on the garbage collector to handle memory cleanup. You create objects, and when they are no longer needed, the GC comes along and takes out the trash.
Rust does not have a garbage collector. It uses ownership and borrowing to manage memory. Lifetimes are how Rust keeps track of how long references are valid. They are the glue that ties Rust’s memory safety model together.