Initial commit
This commit is contained in:
16
exercises/16_lifetimes/lifetimes3.rs
Normal file
16
exercises/16_lifetimes/lifetimes3.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
// Lifetimes are also needed when structs hold references.
|
||||
|
||||
// TODO: Fix the compiler errors about the struct.
|
||||
struct Book<'a> {
|
||||
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