rustlings/exercises/16_lifetimes/lifetimes3.rs

18 lines
341 B
Rust
Raw Normal View History

2022-07-15 13:01:32 +01:00
// Lifetimes are also needed when structs hold references.
struct Book {
author: &str,
title: &str,
}
fn main() {
let name = String::from("Jill Smith");
let title = String::from("Fish Flying");
2024-04-17 22:34:27 +01:00
let book = Book {
author: &name,
title: &title,
};
2022-07-15 13:01:32 +01:00
println!("{} by {}", book.title, book.author);
}