rustlings/exercises/16_lifetimes/lifetimes3.rs

18 lines
341 B
Rust
Raw Normal View History

2022-07-15 12:01:32 +00: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 21:34:27 +00:00
let book = Book {
author: &name,
title: &title,
};
2022-07-15 12:01:32 +00:00
println!("{} by {}", book.title, book.author);
}