---
source: https://iinventedlight.com/library/notes/rust-enums.md
title: "Rust enums: one of a set of possible variants"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "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); 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); prose restates or closely paraphrases cited source lines"
license_family: rust-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Rust"
tags: ['rust', 'enums', 'types']
sources:
  - id: S1
    title: "Defining an Enum - The Rust Programming Language"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
    accessed: 2026-11-04
    license: "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)"
  - id: S2
    title: "Enums - Rust By Example"
    publisher: Rust by Example
    url: https://doc.rust-lang.org/rust-by-example/custom_types/enum.html
    accessed: 2026-11-04
    license: "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)"
---
# 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

- Any IP address can be either a version four or a version six address, but not both at the same time. (S1)
- That property of IP addresses makes the enum data structure appropriate because an enum value can only be one of its variants. (S1)
- Note that the variants of the enum are namespaced under its identifier, and we use a double colon to separate the two. (S1)
- IpAddrKind::V4 and IpAddrKind::V6 are of the same type: IpAddrKind. (S1)

## Variants and aliases

- Any variant which is valid as a struct is also valid in an enum. (S2)
- If you use a type alias, you can refer to each enum variant via its alias. (S2)
- This might be useful if the enum's name is too long or too generic, and you want to rename it. (S2)
- The most common place you'll see this is in impl blocks using the Self alias. (S2)

## Claims
- id: C1
  claim: An enum value can only be one of its variants.
  source: S1
  evidence: "structure appropriate because an enum value can only be one of its variants."
- id: C2
  claim: Enum variants are namespaced under the enum and use a double colon.
  source: S1
  evidence: "use a double colon to separate the two."
- id: C3
  claim: Any variant valid as a struct is valid in an enum.
  source: S2
  evidence: "Any variant which is valid as a struct is also valid in"

## Sources
- [S1] Defining an Enum - The Rust Programming Language. The Rust Programming Language. https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html . License: 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). Accessed 2026-11-04.
- [S2] Enums - Rust By Example. Rust by Example. https://doc.rust-lang.org/rust-by-example/custom_types/enum.html . License: 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). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
