Skip to content

Improve introduction event match block #35

@regexident

Description

@regexident

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions