mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs: add axample of escaping a v keyword in enums (#8425)
This commit is contained in:
parent
4a955d9c54
commit
b8d93df55e
15
doc/docs.md
15
doc/docs.md
@ -1928,6 +1928,21 @@ match color {
|
|||||||
Enum match must be exhaustive or have an `else` branch.
|
Enum match must be exhaustive or have an `else` branch.
|
||||||
This ensures that if a new enum field is added, it's handled everywhere in the code.
|
This ensures that if a new enum field is added, it's handled everywhere in the code.
|
||||||
|
|
||||||
|
Enum fields cannot re-use reserved keywords. However, reserved keywords may be escaped
|
||||||
|
with an @.
|
||||||
|
|
||||||
|
```v
|
||||||
|
enum Color {
|
||||||
|
@none
|
||||||
|
red
|
||||||
|
green
|
||||||
|
blue
|
||||||
|
}
|
||||||
|
|
||||||
|
color := Color.@none
|
||||||
|
println(color)
|
||||||
|
```
|
||||||
|
|
||||||
### Sum types
|
### Sum types
|
||||||
|
|
||||||
A sum type instance can hold a value of several different types. Use the `type`
|
A sum type instance can hold a value of several different types. Use the `type`
|
||||||
|
Loading…
Reference in New Issue
Block a user