mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 05:52:23 -05:00
19 lines
432 B
Rust
19 lines
432 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 {
|
|
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);
|
|
}
|