rustlings/lifetimes/lifetimes3.rs
2024-06-23 02:38:20 -04:00

25 lines
477 B
Rust

// lifetimes3.rs
//
// Lifetimes are also needed when structs hold references.
//
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
// hint.
// I AM DONE
struct Book<'a> {
author: &'a str,
title: &'a str,
}
fn main() {
let name = String::from("Jill Smith");
let title = String::from("Fish Flying");
let book = Book {
author: &name,
title: &title,
};
println!("{} by {}", book.title, book.author);
}