feat: add lifetimes exercises

This commit is contained in:
jayber
2022-07-15 14:01:32 +02:00
committed by mokou
parent 1cc5df0e14
commit 1ef8dacaf6
5 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
// 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 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);
}