Development · Evolving reference
Enums & pattern matching
Named cases, explicit payloads.
Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →
One enum family
enum Color : u8 {
Red;
Green;
Blue;
}
enum SocketRead {
Data { Bytes: readonly byte[]; };
WouldBlock;
Closed;
Failure { Code: i32; };
}Payloadless and payload-carrying cases share one declaration family. Tagged values are inline; declaring an enum does not allocate.
Construction
let Red = Color.Red;
let Closed: SocketRead = .Closed;Payloadless variants are values, without empty call parentheses. Payloads use named field initializers. Expected-type context permits a leading-dot variant spelling.
Matching
switch selects arms with case Pattern => ... and can bind named payload fields. Exhaustive enum matching makes the handled cases visible. See Result for a complete recoverable output example.
Native representation
A tagged enum is distinct from an untagged raw union. Do not assume the target-specific layout is a C ABI promise.
Documentation snapshot: October 24, 2026 About versions ↗