summaryrefslogtreecommitdiff
path: root/solutions/16_lifetimes/lifetimes3.rs
blob: 16a5a6840c40ba23f39431ea5625375b47d14003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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);
}