Skip to content

Structs, enums, methods

Plain records. Fields are laid out in declaration order, addressed by name in source.

open in playground →

The receiver goes between function and the name. Calls dispatch by receiver type at the call site.

open in playground →

Tagged unions with optional positional payloads. The standard library injects Option[T] and Result[T, E], so you don’t re-declare them.

open in playground →

The checker fails the build if a match misses a variant, unless a wildcard _ arm acknowledges the gap.

function describe(s: Shape): string {
match (s) {
Circle(_) => { return "round"; },
// error: missing variant Rectangle
// ^~~~~
}
}

Next: Modules →