From the course: First Look: Rust

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Enums

Enums - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

Enums

- Let's look at enumerations, also referred to as enums. Enums allow you to define a type by enumerating its possible values. First, we'll define and use an enum to show how an enum can encode meaning along with data. Next, we'll explore a particularly useful enum called Option, which expresses that a value can be either something or nothing. So let's look at a situation where we might want to express in code and see why enums are useful and more appropriate than structs. Let's create a new project... Cargo new enums followed by bin. And let's cd into the project. Now that we have created our project, let's go to Visual Studio Code. Let's look at a situation where we might want to express in code and see why enums are useful and more appropriate than structs in a particular case. Say we need to work with IP addresses. Currently, two major standards are used for IP addresses: Version four and version six. Let's expand a project here and in the meantime rs, let's declare our enum. So…

Contents