Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Rust Programming Tutorial #39 – Enum Methods

13.3K views on YouTube

dcode 42 tutorials here

Did you know you can add functions/methods to your Enum (enumeration) Types in Rust? It’s possible, and quite useful. By implementing your own functions, you can make your code a lot clearer by moving some of the Enum-related logic out of your main functions and into the Enum definition itself.

In this video we look at how we can do this through a simple example, featuring the classic ‘Day’ Enum. We check if a ‘Day’ is a week day by using a custom-defined method.

For your reference:
https://rustbyexample.com/custom_types/enum.html

If this video helped you out and you’d like to see more, make sure to leave a like and subscribe to dcode!