liveBook · Manning

Enum variant

As explained in Refactoring to Rust

An enum variant is one named alternative in an enum's finite set of possible values, optionally containing associated data.

An enum variant is one named alternative within an enum’s predetermined set of possible values. Rust uses variants to represent distinct runtime results, such as the four outcomes of FizzBuzz. section 2.5.1

FizzBuzz result

The NotDivisible(i32) variant preserves the number that produced the result, while match extracts it for printing.

How Refactoring to Rust covers it

How deep it goes
Defines variants, demonstrates matching, and shows associated data; it stops short of broader enum internals.
Examples
Uses FizzBuzz variants, a helper function, match arms, and a data-carrying NotDivisible(i32) variant.
What it assumes
Assumes a small FizzBuzz function and introduces enum-based result representation incrementally.
What you can do after
Build it from scratch by defining variants, returning them from functions, and matching each result.
How it connects
Connects enum variants with enums, match expressions, functions, and error handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.