This repository has been archived on 2023-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
rustlings-exercises-completed/exercises/lifetimes/lifetimes3.rs

19 lines
439 B
Rust
Raw Normal View History

2022-07-15 07:01:32 -05:00
// lifetimes3.rs
//
// Lifetimes are also needed when structs hold references.
//
// Execute `rustlings hint lifetimes3` or use the `hint` watch subcommand for a hint.
2023-03-24 16:18:51 -05:00
struct Book<'a> {
author: &'a str,
title: &'a str,
2022-07-15 07:01:32 -05:00
}
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);
}