From the course: Rust Essential Training
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Challenge: Implement the display trait - Rust Tutorial
From the course: Rust Essential Training
Challenge: Implement the display trait
- [Narrator] Surprise. It's challenge time again. This time to practice implementing traits. Your goal this time is to implement the display trait for a custom struct representing a satellite. Display is a fairly common trait which gives data types the ability to produce user facing output. To complete this challenge you'll need to refer to the documentation for the display trait shown here to implement the required methods. I've included this code in the exercise files as a starting point. Which defines a custom struct named, Satellite. And then in the main function, initializes a satellite for the Hubble Space Telescope. And then calls the print macro on it. You can replace the comment on line six with your own code to implement the display trait for a satellite. I'll leave the exact text of what it displays up to you. But you should at least include the satellite's name and velocity. As a hint, in order to implement the…
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)
Implement traits4m 33s
-
(Locked)
Default trait implementation1m 33s
-
(Locked)
Derive traits3m 58s
-
(Locked)
Trait bounds3m 8s
-
(Locked)
Multiple trait bounds5m 16s
-
(Locked)
Return types with implemented traits3m 40s
-
(Locked)
Challenge: Implement the display trait1m 16s
-
(Locked)
Solution: Implement the display trait1m 53s
-
(Locked)
-
-
-
-
-