You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rustlings/exercises/16_lifetimes/lifetimes3.rs

18 lines
341 B
Rust

// Lifetimes are also needed when structs hold references.
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);
}