Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Book Struct

Define a struct called Book with three fields: title (String), author (String), and pages (i32). Create a book with title "The Hobbit", author "Tolkien", and 310 pages. Then print a summary.

Expected output:

text
The Hobbit by Tolkien (310 pages)

Hints:

  • Define all three fields in the struct
  • Use String::from(...) for the text fields
  • Print with println!("{} by {} ({} pages)", ...)
rust
fn main() {
}