rustlings/exercises/lifetimes/lifetimes3.rs
S P 7c317f0779
Steo (#4)
* hashmaps

* quiz, options

* error01

* errors, generics

* traits, quiz3

* lifetime, tests

* iterators, smart pointers
2023-08-05 21:26:54 +01:00

20 lines
442 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);
}