rustlings/exercises/lifetimes/lifetimes3.rs
murasame e64cd1f82e progress 82 percent
Change-Id: I5ec2fda8ecab66c8ee6fcf42ea32b4ffd915ea98
2023-05-25 14:59:03 +08:00

19 lines
439 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.
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);
}