Skip to content

Feedback on rust book > Patterns #24388

Closed
@happybeing

Description

@happybeing

I'm reading the book in section order and some sections have obvs been switched and the text still assumes the old order. I'm just going to mention that but not point out the occurrences here. However, it may explain some of my confusion, if a section I'm commenting on is silently assuming I've read something that now occurs later.

Firstly, I like Rust and am enjoying reading about it. The most confusing bit so far (a testament to how good the book has been) is "match" which has a very simple example, and "patterns" which uses match to illustrate a several patterns: https://doc.rust-lang.org/book/patterns.html

I can't tell from this what these code samples do, or what most of the patterns mean. Example output would help clarify this, but some of the descriptions probably still need expanding too.

I couldn't make sense of patterns based on these examples.

Match guards appear to show overlapping cases (e.g. "5" would match both "OptionalInt::Value(i) if i > 5" and "OptionalInt::Value(..)"). Does match allow overlapping patterns? If so, what is the behaviour - first match only?

I don't understand how the "ref and ref mut" patterns work - the example seems to just show a matching example. In general the examples don't show what matches and why, what doesn't etc. which leaves a big gap in my understanding.

There may be some implicit knowledge that renders all this clear, but I haven't gained it by reading the book in order to this point.

So far this is the only thing I know I don't understand, which is pretty damn good if true :-)
Also, where's the regexp pattern!? ;-)

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