rustlings/exercises/16_lifetimes/lifetimes3.rs

18 lines
341 B
Rust
Raw Normal View History

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