# Zig Level 4: Structs, Enums & Unions

> Level 4: Structs, Enums & Unions of the LoWisa Zig course: Structs, Enums, Tagged Unions. 3 lessons and 9 ideas, each explained in one line.

Structs, Enums & Unions is level 4 of 11 of the [LoWisa Zig course](/courses/zig/). It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

## Structs

- **Structs and methods.** A **struct** holds fields and declares functions: methods as namespaced fns taking self.
- **Defaults and init.** Fields take **default** values; init functions build valid instances: construction explicit.
- **Anonymous structs.** Anonymous **struct** literals pass options: .{ .retries = 3 }: named arguments by shape.

## Enums

- **Enums.** An **enum** names a closed set: switch over it is exhaustive, checked forever.
- **Tagged values.** Enums carry integer **tags** when needed: @intFromEnum crossing to numbers explicitly.
- **Non-exhaustive enums.** An enum can be **open** (_) for forward compatibility: the escape declared, not accidental.

## Tagged Unions

- **Tagged unions.** A **union(enum)** stores one variant plus its tag: Zig’s sum type, switch-destructured.
- **Payload capture.** switch captures the **payload**: case .circle => |radius|: data bound as it matches.
- **Modelling with unions.** Tagged unions model states honestly: a Message that cannot be two things at **once**.

## Before and after this level

- **Before:** [Level 3: Allocators](/courses/zig/level-3-allocators/): Explicit Allocation, Allocator Interfaces, Designing Memory Ownership.
- **Next:** [Level 5: Errors & Optionals](/courses/zig/level-5-errors-and-optionals/): Error Unions, Optionals, Explicit Failure Handling.

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See [Checkpoints and flashcards](/help/checkpoints-and-flashcards/).

## Frequently asked questions

### What does Zig Level 4: Structs, Enums & Unions cover?

Structs, Enums, Tagged Unions: 3 lessons and 9 ideas.

### What should I know before this level?

The level before it, Level 3: Allocators, which covers Explicit Allocation, Allocator Interfaces, Designing Memory Ownership.

## Learn Zig on your phone

The first level is free. LoWisa is on Google Play and the App Store.

---

Source: https://lowisa.dev/courses/zig/level-4-structs-enums-and-unions/ · Updated 2026-11-25
