rustlings/exercises/16_lifetimes/lifetimes3.rs

18 lines
341 B
Rust
Raw Normal View History

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