When dealing with complex data structures or APIs, you may need to specify lifetimes explicitly to ensure that references are managed correctly. This section will cover advanced cases, such as struct lifetimes, method lifetimes, and multiple lifetimes.
struct ImportantExcerpt<'a> {
part: &'a str,
}
fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let i = ImportantExcerpt { part: first_sentence };
println!("Excerpt: {}", i.part);
}