google / google/comprehensive-rust

syntax: explain that rust pervasively allows separators to be used as terminators

Open
#2,071 0 comments 1 reaction 1 assignee Claimed by @fw-immunant View on GitHub
good first issue
Dominant language
Rust
Stars
33.4k
Forks
2.1k
Avg merge
1d 3h
Merged PRs (30d)
10

Description

I don't think we have it anywhere in our speaker notes, but we should make an explicit mention of it. Usually when teaching I try to bring this up around when semicolons are discussed or when we talk about tuple and array types.

This is a nice feature of the language that's easy to miss if not called out: to minimize git diffs, almost every syntactic construct in Rust allows separators to also be used as terminators. This includes commas in tuple and array values, semicolons separating expressions (though the trailing semicolon does have semantic meaning in this case), and even pipes as leading delimiters in patterns (as in Standard ML or OCaml):
```
match 'x' {
| 'a' => 1,
| 'b'
| 'c' => 2,
| _ => 3,
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.