Skip to content

I'm having trouble at enums2.rs #2079

Closed Answered by mo8it
nasccped asked this question in Q&A
Discussion options

You must be logged in to vote

There are two ways to use your own struct inside an enum.

The first one is to have an "anonymous struct" like the following:

enum Message {
    Move { x: u64, y: u64 },
    // …
}

The second one is to have a named struct defined separately (what you want for Move):

struct Point {
    x: u64,
    y: u64,
}

enum Message {
    Move(Point),
    // …
}

The updated exercise wants you to practice both variants since Resize has the first one.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nasccped
Comment options

Answer selected by mo8it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2078 on August 08, 2024 23:35.