From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Challenge: Represent a location - Rust Tutorial
From the course: Rust Essential Training
Challenge: Represent a location
(upbeat music) - [Instructor] It's been a while since our last challenge, so let's have another one. this time, to practice defining enums. Your goal for this challenge is to define an enum named Location to represent, well, a location. The location can be one of three possible variants. It could be unknown, anonymous or known, in which case it should store values for the latitude and longitude as floats. In addition to defining the Location enum, you should also implement a method named Display which prints information about the location to standard output. The message it prints should differ based on the variant. So for example, if the address is unknown, it might say that it's an unknown address. And if it's known, then it would display the latitude and longitude. This example program instantiates several locations and then calls the display method on them. I've included it in the exercise files for you to use to…
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)
-
-
-