Skip to content

Commit

Permalink
Updated enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Feb 29, 2024
1 parent d720ec5 commit 864dcb6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/content/docs/references/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ fn void demo_enum(Height h)

Enums are always namespaced.

Enums also define `.min` and `.max`, returning the minimum and maximum value for the enum values. `.values` returns an array with all enums.
Enum support various reflection properties: `.values` returns an array with all enums. `.len` or `.elements` returns the number
of enum values, `.inner` returns the storage type. `.names` returns an array with the names of all enums. `.associated`
returns an array of the typeids of the associated values for the enum.

```c3
enum State : uint
Expand All @@ -158,10 +160,9 @@ enum State : uint
STOP,
}
const uint LOWEST = State.min;
const uint HIGHEST = State.max;
State start = State.values[0];
usz enums = State.elements; // 2
String[] names = State.names; // [ "START", "STOP" ]
```

#### defer
Expand Down Expand Up @@ -198,7 +199,7 @@ fn void! test(int x)
defer io::printn("");
defer io::printn("A");
defer try io::printn("X");
defer catch io::printn("B")
defer catch io::printn("B");
defer catch (err) io::printfn("%s", err.message);
if (x == 1) return FooError!;
print("!")
Expand Down

0 comments on commit 864dcb6

Please sign in to comment.