mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-11-29 22:47:43 +02:00
lifetimes3 solution
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user