2022-07-15 13:01:32 +01:00
|
|
|
// lifetimes3.rs
|
|
|
|
//
|
|
|
|
// Lifetimes are also needed when structs hold references.
|
|
|
|
//
|
2023-05-29 18:39:08 +01:00
|
|
|
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a
|
|
|
|
// hint.
|
2022-07-15 13:01:32 +01:00
|
|
|
|
|
|
|
// I AM NOT DONE
|
|
|
|
|
|
|
|
struct Book {
|
|
|
|
author: &str,
|
|
|
|
title: &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);
|
|
|
|
}
|