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.

Solution: Implement the display trait

Solution: Implement the display trait - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Solution: Implement the display trait

(upbeat music) - [Instructor] To solve the challenge to implement the display trait, I started by looking at the documentation page for that trait shown here. A little ways down the page, it describes the method that's required for something to implement the display trait. This fmt, or format method, has a somewhat complex signature, so to make things easier on me, I'll simply copy the example display implementation from this documentation, and then paste that into my code. I'll replace the name, position, with the name of my satellite struct, and then modify the contents of the right macro with the string that says the satellite's name and its velocity. And finally, since the display trait is referenced in relation to the format module, I'll import that format module at the top of the program. And that's it, now our custom satellite struct can be used with a print macro, like most other common datatypes. To…

Contents