doc: add more enum examples (#7510)

pull/7525/head
Andréas Livet 2020-12-23 19:14:55 +01:00 committed by GitHub
parent 214290d55b
commit f66569ee1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -1781,12 +1781,25 @@ mut color := Color.red
// V knows that `color` is a `Color`. No need to use `color = Color.green` here.
color = .green
println(color) // "green"
// enum starts by default at 0
println(color == 1) // true
match color {
.red { println('the color was red') }
.green { println('the color was green') }
.blue { println('the color was blue') }
}
// It's possible to override enum values
enum Size {
small = -1
medium = 0
large = 1
}
mut s := Size.small
println(s == -1) // true
```
Enum match must be exhaustive or have an `else` branch.