In the following code:
struct Book {
pages: i32,
rating: i32,
}
fn display_page_count(book: &Book) {
println!("Pages = {:?}", book.pages);
}
fn display_rating(book: &Book) {
println!("Rating = {:?}", book.rating);
}
fn main() {
let book = Book {
pages: 5,
rating: 9,
};
display_page_count(&book);
display_rating(&book);
}
Why do we write fn display_page_count(book: &Book) and not fn display_page_count(&book: Book)? For me, book is the data we’ll want to borrow later, Book is just a type (a struct here), so I don’t understand why we have to borrow the type and not the variable or parameter. Can someone tell me why I’m wrong?