Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm having trouble at enums2.rs #2078

Closed
nasccped opened this issue Aug 8, 2024 · 0 comments
Closed

I'm having trouble at enums2.rs #2078

nasccped opened this issue Aug 8, 2024 · 0 comments

Comments

@nasccped
Copy link

nasccped commented Aug 8, 2024

I'm new at Rust language and I'm having a lot of fun with the lang, rustlings and ytb videos, but, doing some rustlings exercises, i became stucked at enums2.rs.


I'll try to be as brief as possible:

I spent a time looking at enums2.rs solutions on gitHub Gist and I realize that the solutions was made through an older rustlings version.

On the link marked above, we have something like this:

#[derive(Debug)]
enum Message {
    // TODO: define the different variants used below
}

impl Message {
    fn call(&self) {
        println!("{:?}", &self);
    }
}

fn main() {
    let messages = [
        Message::Move{ x: 10, y: 30 }, // NOTE: that line it's important <<<
        Message::Echo(String::from("hello world")),
        Message::ChangeColor(200, 255, 255),
        Message::Quit
    ];

    for message in &messages {
        message.call();
    }
}

But, in my local rustlings, i have something like:

fn main() {
    let messages = [
        Message::Resize {
            width: 10,
            height: 30,
        },
        Message::Move(Point { x: 10, y: 15 }), // NOTE: is exactly this line <<<
        Message::Echo(String::from("hello world")),
        Message::ChangeColor(200, 255, 255),
        Message::Quit,
    ];

    for message in &messages {
        message.call();
    }
}

To solve the exercise, i did:

#[derive(Debug)]
enum Message {
    // TODO: Define the different variants used below.
    Resize { width: i32, height: i32 },
    Move( Point { x: i32, y: i32 } ),
    Echo(String),
    ChangeColor(i32, i32, i32),
    Quit
}

but, when running the program, I've got:

error: expected one of `!`, `(`, `)`, ` `, `,`, `::`, or `<`, found `{`
  --> exercises/08_enums/enums2.rs:13:17
   |
10 | enum Message {
   |      ------- while parsing this enum
...
13 |     Move( Point { x: i32, y: i32 } ),
   |                 ^ expected one of 7 possible tokens
   |
   = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`

error[E0061]: this enum variant takes 0 arguments but 1 argument was supplied
  --> exercises/08_enums/enums2.rs:31:9
   |
31 |         Message::Move(Point { x: 10, y: 15 }), // NOTE: is exactly this line <<<
   |         ^^^^^^^^^^^^^ ----------------------
   |                       |
   |                       unexpected argument of type `Point`
   |                       help: remove the extra argument
   |
note: tuple variant defined here
  --> exercises/08_enums/enums2.rs:13:5
   |
13 |     Move( Point { x: i32, y: i32 } ),
   |     ^^^^

For more information about this error, try `rustc --explain E0061`.
error: could not compile `exercises` (bin "enums2") due to 2 previous errors

The way that I think doesn't seem to be wrong. I know exactly what i need to do to beat the task, but that doesn't seem like the way I should do it. Can someone help me?

@rust-lang rust-lang locked and limited conversation to collaborators Aug 8, 2024
@mo8it mo8it converted this issue into discussion #2079 Aug 8, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant