rustlings/exercises/16_lifetimes/lifetimes3.rs

17 lines
314 B
Rust
Raw Permalink Normal View History

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