diff options
Diffstat (limited to 'solutions/16_lifetimes/lifetimes3.rs')
| -rw-r--r-- | solutions/16_lifetimes/lifetimes3.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/solutions/16_lifetimes/lifetimes3.rs b/solutions/16_lifetimes/lifetimes3.rs index 4e18198..16a5a68 100644 --- a/solutions/16_lifetimes/lifetimes3.rs +++ b/solutions/16_lifetimes/lifetimes3.rs @@ -1 +1,18 @@ -// Solutions will be available before the stable release. Thank you for testing the beta version 🥰 +// 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); +} |
