-
Notifications
You must be signed in to change notification settings - Fork 11k
Open
Description
08_enums/enum2.rs code defines an array of messages:
let messages = [
Message::Resize {
width: 10,
height: 30,
},
Message::Move(Point { x: 10, y: 15 }),
Message::Echo(String::from("hello world")),
Message::ChangeColor(200, 255, 255),
Message::Quit,
];
For newcomers, this syntax can be confusing,especially without type inlay hints.
It looks very similar to a single struct initialization rather than an array of multiple enum variants. The messages variable can easily be mistaken for one instance of a Message instead of a list of different ones.
If someone is learning Rust enum syntax for the first time, the messages array initialization resembles a struct initialization (which users have it fresh in memory because they are the preceding exercises).
I think the exercise will benefit from having some individual definitions first, and then the messages array.
Something like:
let move_point = Message::Move(Point { x: 100, y: 50 });
let echo = Message::Echo(String::from("Comms up"));
let messages = [
Message::Resize {
width: 10,
height: 30,
},
Message::Move(Point { x: 10, y: 15 }),
Message::Echo(String::from("hello world")),
Message::ChangeColor(200, 255, 255),
Message::Quit,
];
Metadata
Metadata
Assignees
Labels
No labels