Rust’s Enums Explained

Oliver Jumpertz
7 min readMay 7, 2023
Rust’s Enums Explained

In programming, an enumerated type is a type that consists of a set of values. This basically makes them a union. Many programming languages thus provide something like enums for developers to use. In many of these languages, enums are only a type alias over an integer or a string.

Rust takes enums a whole level further by providing developers with variadic types that can actually contain other types and be as different from each other as possible. They are even so important in Rust that they form an essential building block of many programs. Especially as Rust misses inheritance, enums are often the way to go when developers want to write logic only once and use it for many associated tasks without using techniques like composition.

Every Rust developer should have deep knowledge about enums, which this article will be about.

If you enjoy watching a short video about this topic more, I have published one to YouTube that you might enjoy watching:

Enum Basics

--

--