docs: update wording & fix typo

pull/5387/head
joe-conigliaro 2020-06-19 01:52:21 +10:00
parent 98a48ecfb9
commit f526754535
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
1 changed files with 5 additions and 3 deletions

View File

@ -1194,23 +1194,25 @@ There are 3 ways to access the cast variant inside a match branch:
fn unary_expr(ux UnaryExpr) {...}
fn if_expr(ix IfExpr) {...}
// using `it`
// using `it`
match expr {
BinaryExpr { binary_expr(it) }
...
}
// using the shadowed variable, in this case `expr`
// using the shadowed variable, in this case `expr`
match expr {
UnaryExpr { unary_expr(expr) }
...
}
// using `as` so specify a variable
// using `as` to specify a variable
match expr as actual_expr {
IfExpr { if_expr(actual_expr) }
...
}
```
Note: shadowing only works when the match expression is a variable. It will not work on struct fields, arrays indexing, or map key lookup.
## Option/Result types and error handling
```v