Skip to content
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

Improve introduction event match block #35

Open
regexident opened this issue Nov 23, 2019 · 1 comment
Open

Improve introduction event match block #35

regexident opened this issue Nov 23, 2019 · 1 comment

Comments

@regexident
Copy link
Contributor

There's a lot to digest in this snippet …

match event {
    Event::KeyDown {
        keycode: Some(Keycode::Escape),
        ..
    } => break 'game,
    _ => continue 'game,
}

With barely any prior introduction to the features shown it ends up hitting newcomers to Rust in the face like a wrecking ball.

It got them all:

  • enum with associated values.
  • multi-level destructuring
  • Some(…) (which hides an Option::Some by eliding the Option::)
  • ..
  • 'game (I can count the number of times I've seen a label like this be used in the wild on one hand)
  • break vs. continue
  • _
  • =>

To make things worse: with the exception of "break vs. continue" none of these things can easily be searched for either.

The continue 'game should probably also be just continue, as else one could end up dropping events, that should be handled.

--

Over all it might make sense to add links to corresponding references in Rust by Example when introducing new concepts and syntax.

@jonas-schievink
Copy link

Yeah, that's a lot to digest all at once, though my ggez rewrite obsoletes that code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants