flâneur — a map of the web's best reading

Defining an Enum - The Rust Programming Language

doc.rust-lang.org · 2,855 words · saved by 3 readers

Enums are a way of defining custom data types in a different way than you do with structs. Let’s look at a situation we might want to express in code and see why enums are useful and more appropriate than structs in this case. Say we need to work with IP addresses. Currently, two major standards are used for IP addresses: version four and version six. Because these are the only possibilities for an IP address that our program will come across, we can enumerate all possible variants, which is where enumeration gets its name.

Defining an Enum - The Rust Programming Language Keyboard shortcuts Press ← or → to navigate between chapters Press S or / to search in the book Press ? to show this help Press Esc to hide this help Auto Light Rust Coal Navy Ayu The Rust Programming Language Defining an Enum Where structs give you a way of grouping together related fields and data, like a Rectangle with its width and height , enums give you a way of saying a value is one of a possible set of values. For example, we may want to say that Rectangle is one of a set of possible shapes that also includes Circle and Triangle . To do

Explore this link on the map →

saved by

related reading