docs: update match as syntax (#8056)

pull/8068/head
Daniel Däschle 2021-01-12 12:10:44 +01:00 committed by GitHub
parent d4237aa7af
commit 4ffe3d83b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 16 deletions

View File

@ -1975,10 +1975,6 @@ fn land(w World) {
`match` must have a pattern for each variant or have an `else` branch.
There are two ways to access the cast variant inside a match branch:
- the shadowed match variable
- using `as` to specify a variable name
```v ignore
struct Moon {}
struct Mars {}
@ -1997,21 +1993,9 @@ fn pass_time(w World) {
Mars { w.shiver() }
else {}
}
// using `as` to specify a name for each value
match w as var {
Mars { var.shiver() }
Venus { var.sweat() }
else {
// w is of type World
assert w is Moon
}
}
}
```
Note: shadowing only works when the match expression is a variable.
It will not work on struct fields, array indexes, or map keys.
### Option/Result types and error handling
Option types are declared with `?Type`: