Перейти к содержимому

Rust Lifetimes, Finally Visualized (Full Course)

Rust It Over

0:00 / 0:00

Rust Lifetimes, Finally Visualized (Full Course)

467 просмотров · 3 недели назад
Rust It Over
372 подписчика
467 просмотров · 3 недели назад
Lifetimes are the part of Rust everyone memorises wrong. This is the whole model, animated - 16 chapters, from "a lifetime is not a scope" to why the borrow checker still says no to code that is provably fine. Every snippet in this video was compiled and run on rustc 1.98.0 (edition 2021) while it was written, and every compiler message on screen is real output. Chapter 1 shows the same file rejected by an eight-year-old compiler and accepted by today's - both toolchains installed, both outputs verbatim. What you'll actually take away: · A lifetime is a REGION — the set of places a reference still has to be valid — not a scope, and not a duration. · What the compiler is really asking when it demands an annotation (hint: it's routing, not time). · Why writing 'a never makes anything live longer. · The three elision rules, and the trap in rule three that keeps a struct borrowed for life. · The two completely different jobs of 'static, and why confusing them is the most-corrected sentence in Rust. · Why &mut is different from & at the type level — and what that has to do with 2030 and 2027. · Why the one struct you can't write is blocked by the borrow rule, not by dangling pointers. Timestamps: 0:00 A Lifetime Is Not a Scope 1:16 A Region Has Holes 2:29 The Question the Compiler Is Asking 3:34 A Slot, Not a Grant 4:26 One Lifetime, or Two 5:34 Why You Almost Never Write One 6:53 Rule Three, and the Trap in It 8:01 Structs That Borrow 9:22 There Are Two 'statics 10:34 The Wall: Threads 11:56 Add a Destructor, Change the Rules 13:20 Why &mut Is Different 14:43 The One You Can't Write 16:14 None of It Survives 17:36 Where the Checker Still Says No 18:58 The Whole Thing, One Breath Watch the previous chapter first if ownership still feels shaky: ▶ Rust Ownership & Borrowing, Finally Visualized —    • Rust Ownership & Borrowing, Finally Visual...   — Rust, visualized. No fluff, no filler. — ▶ Subscribe:    / @rustitover   🦀 TikTok:   / rust.it.over   #rust #rustlang #programming #lifetimes #borrowchecker