docs: update wording & fix typo
parent
98a48ecfb9
commit
f526754535
|
@ -1194,23 +1194,25 @@ There are 3 ways to access the cast variant inside a match branch:
|
||||||
fn unary_expr(ux UnaryExpr) {...}
|
fn unary_expr(ux UnaryExpr) {...}
|
||||||
fn if_expr(ix IfExpr) {...}
|
fn if_expr(ix IfExpr) {...}
|
||||||
|
|
||||||
// using `it`
|
// using `it`
|
||||||
match expr {
|
match expr {
|
||||||
BinaryExpr { binary_expr(it) }
|
BinaryExpr { binary_expr(it) }
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
// using the shadowed variable, in this case `expr`
|
// using the shadowed variable, in this case `expr`
|
||||||
match expr {
|
match expr {
|
||||||
UnaryExpr { unary_expr(expr) }
|
UnaryExpr { unary_expr(expr) }
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
// using `as` so specify a variable
|
// using `as` to specify a variable
|
||||||
match expr as actual_expr {
|
match expr as actual_expr {
|
||||||
IfExpr { if_expr(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
|
## Option/Result types and error handling
|
||||||
|
|
||||||
```v
|
```v
|
||||||
|
|
Loading…
Reference in New Issue