Exercise 4 · Chapter: Tuples & StructsRequired+50 XP
Pet Struct
Define a struct called Pet with two fields: name (String) and species (String). Create a pet named "Buddy" who is a "dog", then print its info.
Expected output:
Buddy is a dog
Hints:
- Define the struct outside
main:struct Pet { name: String, species: String } - Use
String::from("Buddy")for String values - Access fields with
pet.nameandpet.species
rust
fn main() {
}
Output
Run your code to see the output here.