← All notes

Rust enums: one of a set of possible variants

Answer: Where structs give you a way of grouping together related fields and data, enums give you a way of saying a value is one of a possible set of values. (S1) The enum keyword allows the creation of a type which may be one of a few different variants. (S2)

The IP address example

Variants and aliases

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Defining an Enum - The Rust Programming Language, MIT or Apache-2.0 (rust-lang/book; Copyright (c) 2010 The Rust Project Developers; https://github.com/rust-lang/book/blob/main/LICENSE-MIT); Rust by Example, Enums - Rust By Example, MIT or Apache-2.0 (rust-lang/rust-by-example; Copyright (c) 2014 Jorge Aparicio; https://github.com/rust-lang/rust-by-example/blob/master/LICENSE-MIT).

Cite this

Permanent ID: iil:note:j1a58wns

iinventedlight. 2026. "Rust enums: one of a set of possible variants." iinventedlight Library, iil:note:j1a58wns, version of 2026-11-04. https://iinventedlight.com/library/notes/rust-enums/. License: CC-BY-4.0.

@misc{iil_note_j1a58wns,
  author = {{iinventedlight}},
  title = {{Rust enums: one of a set of possible variants}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/rust-enums/},
  note = {Permanent ID iil:note:j1a58wns. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/rust-enums.md.