Skip to content
0:00 / 0:00

#rustlifetimes#rustgenerics#jongjengset

Crust of Rust: Lifetime Annotations

Jon Gjengset

111K subscribers • 7 videos on Hallway

YouTube
  • Recommended by 3 people: 3 on Hacker News.
  • Presented by Jon Gjengset, software engineer and author

Intermediate. Assumes working knowledge.

298K views6 years ago3 recommendations

Programming languagesSystems programmingRustMemory managementConcurrency and parallelism

Jon Gjengset live-codes a string splitting utility to explain why and how to use multiple explicit lifetime annotations in Rust.

In the 2019 Rust Survey, a lot of people were asking for video content covering intermediate Rust content. So in this first video (possibly of many), we're going to investigate a case where you need multiple explicit lifetime annotations. We explore why they are needed, and why we need more than one in this particular case. We also talk about some of the differences between the string types and introduce generics over a self-defined trait in the process. And don't worry, I know that what we're implementing exists in the standard library :) Introduction Start a rust project Struct and method definitions for StrSplit and first test How you decide between a library and a binary Start implementing StrSplit When to use match vs if let some Doesn't compile! missing lifetime specifier Can I be wrong by specifying lifetimes? Anonymous lifetime '_ Order lifetimes based on how long they are Anonymous lifetime '_ (with multiple lifetimes) Compile error: lifetime of reference outlives lifetime of borrowed content Static lifetime Bug when a delimiter tails a string What is the ref keyword and why not & What's the * on the left of remainder What is take() doing Mutable references are one level deep Solving a hang with as_mut() Multiple lifetimes, implementing until_char Difference between a str and a String Multiple lifetimes (continued) Generic delimiter (Delimiter trait) char length utf8 Standard library split Q&A You can find the final code at gist.github.com/jonhoo/2a7fdcf79be03e51a5f95cd326f2a1e8. You can watch the live version with comments at youtube.com/watch?v=Oxaex566Irg

Why it's here

3 people recommend this

What people say. Engineers point newcomers here for the clearest and most thorough explanation of Rust lifetimes.

harikbon Hacker News • Recommends

On “There’s plenty of room at the Top: computer performance after Moore’s law”

Anecdotal - One of favorite YouTube live-streaming personalities, Jon Gjengset1 is a Ph.D student at MIT CSAIL. His talks are very detailed4 and captivating3 1 link Talks 2 link 3 link Rust Details(my favorites) 4 link to this video

ashish01on Hacker News • Recommends

On “My Favorite Rust Function Signature”

I also used to feel the same way. But listening to 0Crust of Rust: Lifetime Annotations by Jon Gjengset helped me understand its need. 0 link to this video really helped me understand it.

tialaramexon Hacker News • Recommends

On “Next steps for Rust in the kernel”

…it look, it is a headache in C++ because they added it to a finished working language ] Several people suggested books/ web pages let me suggest some videos: Jon Gjengset's "Crust of Rust" Youtube videos are good once you reach the point where you can write more than "Hello, world!" with some confidence but certain specific things aren't clicking. link to this video For example, Jon does a whole video on lifetime annotations, which are something you won't see in most popular languages, but also one on Rust's iterators, which are a familiar concept from both C++ and Swift but don't work quite like either (they're very different from C++ iterators, your Swift experience will help more). I recommend watch…

ly3xqhl8g9on Hacker News • Mentions

On “Why I Use C When I Believe in Memory Safety”

Rust seems nice when you see someone like Jon Gjengset writing it 1, however when actually writing it yourself you discover that your errors have errors which only show some kind of alien fishing when you Google them. Perhaps ChatGPT could help here, it's quite useful/pleasant for trivial quizzes, however I asked it recently how to handle a file upload using actix-web and it hallucinated some really nice methods, too bad they aren't in the code base. 1 link to this video