mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 14:57:32 -05:00
17 lines
341 B
Rust
17 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);
|
|
}
|