rustlings/exercises/16_lifetimes/lifetimes3.rs

17 lines
314 B
Rust
Raw Normal View History

2022-07-15 12:01:32 +00:00
// Lifetimes are also needed when structs hold references.
2024-06-27 14:15:53 +00:00
// TODO: Fix the compiler errors about the struct.
2022-07-15 12:01:32 +00:00
struct Book {
author: &str,
title: &str,
}
fn main() {
2024-04-17 21:34:27 +00:00
let book = Book {
2024-06-27 14:15:53 +00:00
author: "George Orwell",
title: "1984",
2024-04-17 21:34:27 +00:00
};
2022-07-15 12:01:32 +00:00
println!("{} by {}", book.title, book.author);
}