finish until lifetimes

This commit is contained in:
Samuele Iacoponi
2026-02-27 17:15:07 +01:00
parent b1b81f7e07
commit 8c99d4187d
9 changed files with 148 additions and 23 deletions

View File

@@ -1,4 +1,18 @@
fn main() {
// DON'T EDIT THIS SOLUTION FILE!
// It will be automatically filled after you finish the exercise.
// Lifetimes are also needed when structs hold references.
struct Book<'a> {
// ^^^^ added a lifetime annotation
author: &'a str,
// ^^
title: &'a str,
// ^^
}
fn main() {
let book = Book {
author: "George Orwell",
title: "1984",
};
println!("{} by {}", book.title, book.author);
}