Book: Explanation of "pattern" is still confusing to me.

Created on 4 Oct 2016  路  4Comments  路  Source: rust-lang/book

I was going through the old book and had a hard time fully understanding what exactly a "pattern" is. The book immediately started out by describing _how_ patterns were used in variable bindings and match expressions, but not with any sort of definition of _what_ they actually are.

I looked at the current status of the new book and, while the examples are definitely a bit clearer, the pattern section still seems to focus on the _how_ rather than the _what_.

We've actually used patterns a few times so far: they're used in let bindings, in function arguments, and in the match expression. Patterns have a lot more abilities than we have demonstrated so far, so we'll cover some of the most commonly used ones in this section. Any of these abilities work in any place where a pattern is used.

This simply states we've used patterns before and immediately leads into examples. What would help me understand patterns is to lead with something similar to the following: "a pattern is any ______ which is of the format _______." I attempted to find this information in the reference documentation, but could not find it there, either.

Bug

All 4 comments

It's documented in the reference:

Patterns consist of some combination of literals, destructured arrays or enum constructors, structs and tuples, variable binding specifications, wildcards (..), and placeholders (_).

Thank you for this issue, this is great feedback! 鉂わ笍 I will take a look at this for the section on match in chapter 6, and we are planning on a whole chapter just about patterns later in the book, so I'll make sure it's thoroughly addressed there.

@carols10cents that sounds great, thank you!

@0xmohit thanks for pointing out where I can find it in the reference. I missed it, as it's part of the _match_ reference, which occurs pretty far down when doing a keyword search for _pattern_. The explanation there is very much what I was looking for, though!

I added a sentence to chapter 6 listing some things that are patterns and directing the reader to the chapter all about patterns that's currently slated for chapter 18. So I'm leaving this open, just changing the milestone :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carols10cents picture carols10cents  路  5Comments

dlukes picture dlukes  路  3Comments

binarycrusader picture binarycrusader  路  4Comments

istarus picture istarus  路  4Comments

rpjohnst picture rpjohnst  路  4Comments