Skip to content

Book: enum comment about match needs more detail #22035

Closed
@mdinger

Description

@mdinger

In enum, it was just shown how enum doesn't have equality ops by default among other ops. This should state a (brief) reason why match is useful for many comparison cases (not just that it has pretty branching). I apparently forgot or erased it or something before pushing...

This may seem rather limiting, particularly equality being invalid; in many cases however, it's unnecessary. Rust provides the match keyword, which will be examined in more detail in the next section, which often allows better and easier branch control than a series of if/else statements would. However, for our game we need the comparisons to work so we will utilize the Ordering enum provided by the standard library which supports such comparisons. It has this form:

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