From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Option<T> enum
- In addition to working with values that represent something. In programming we'll often also need to represent the concept that a value could be nothing. Many programming languages use a null value to indicate when there is no value. In those languages, variables can either be null or not null meaning they do have a value. It's a simple and straightforward system. But problems arise when you try to use a null value in something that requires a not null value. It's easy to do by accident and it's a common source of runtime errors. That's not safe. And therefore Rust does not have a null value in the traditional sense like many other languages. Instead, Rust implements the concept using a generic Enum named option, which can be one of two variants. If it's the sum variant that indicates it's not null and does have a value which is stored Enum. Otherwise, if the Enum is the none variant that indicates it does not have…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Define enums3m 43s
-
(Locked)
Match operator2m 43s
-
(Locked)
Match with default placeholder4m 34s
-
(Locked)
Enum methods3m 4s
-
(Locked)
Option<T> enum5m 15s
-
(Locked)
Matching Option<T>1m 31s
-
(Locked)
If-let syntax1m 57s
-
(Locked)
Challenge: Represent a location1m 4s
-
(Locked)
Solution: Represent a location1m 20s
-
(Locked)
-
-
-