Rust Programming Tutorial #39 - Enum Methods

preview_player
Показать описание
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:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

U can remove '&' and "return" in match block

Ivan-qbkc
Автор

Thanks! Would you consider making your vscode dark mode?

irlshrek
Автор

I was just reading docs I did understand structs and enums was a bit difficult for me thanks for this vid

chiragsingla.
Автор

Why did you added & sign front of the Day::Saturday? Does it copies himself?

sbn
Автор

Yo, the # sign is just "hash". A hash tag is what people called it when they tagged a word in twitter with a hash sign in front of it.
Please never call the # a "hash tag" outside of twitter again.

nextlifeonearth