From f66569ee1a60076141ee636498f399cc60bd7e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20Livet?= Date: Wed, 23 Dec 2020 19:14:55 +0100 Subject: [PATCH] doc: add more enum examples (#7510) --- doc/docs.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 5c05dc3569..ee2fb040ca 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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.