Skip to content

Commit

Permalink
docs: add section explaining how to convert enum from/to str/int valu…
Browse files Browse the repository at this point in the history
…es (#20791)
  • Loading branch information
mac-hel committed Feb 12, 2024
1 parent c1b5d82 commit ea2e6e1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion doc/docs.md
Expand Up @@ -3405,6 +3405,31 @@ three
one
```

Enums can be created from string or integer value and converted into string

```v
enum Cycle {
one
two = 2
three
}
// Create enum from value
println(Cycle.from(10) or { Cycle.three })
println(Cycle.from('two')!)
// Convert an enum value to a string
println(Cycle.one.str())
```

Output:

```
three
two
one
```

### Function Types

You can use type aliases for naming specific function signatures - for
Expand Down Expand Up @@ -7521,4 +7546,4 @@ Assignment Operators
+= -= *= /= %=
&= |= ^=
>>= <<= >>>=
```
```

0 comments on commit ea2e6e1

Please sign in to comment.