Skip to content

Discussion of .. pattern does not demo slices nor the idiom [a, b, middle @ .., y, z] #2874

@pnkfelix

Description

@pnkfelix
  • I have checked the latest main branch to see if this has already been fixed
  • I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/stable/book/ch18-03-pattern-syntax.html#ignoring-remaining-parts-of-a-value-with-

Description of the problem:

The discussion of .. shows how to use .. to "ignore" things, and demonstrates it on struct patterns and tuple patterns.

But the book does not show .. in use on slice patterns.

Nor does it demonstrate the (common?) idiom of not ignoring the portion of the slice matched via .., but instead binding it to its own variable, via the pattern IDENT @ .. in the midst of the slice pattern.

Suggested fix:

To be honest, I'm not totally sure. It would be fine to fix the absence of slice demos by just adding one.

But the "Ignoring Values in a Pattern" would be a bit of a weird place to show how not to ignore it. That's what I'm hestiating about. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions