rustlings/exercises/16_lifetimes/lifetimes3.rs

17 lines
314 B
Rust
Raw Normal View History

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