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

Challenge: Represent a location - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

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…

Contents