Enums

You will learn

The two ways to declare an enum and how a switch reads a value.

pub enum Color { Red, Green, Blue } names three cases. The Zig form pub const Mode = enum(u8) { Idle, Run } also fixes the type that stores a case, here u8. A switch over a value lists what each case gives and uses else for the rest. Both forms compile clean on all 7 backends in the lesson spec.

Open the interactive lesson →