My trait and PartialEq

The other way to look at this is that traits and enums are just two different ways to organize the table. If you imagine a table of types vertically vs functions horizontally, with the cells as the behaviour of that function for that type, then drawing circles around the rows is the trait organization and drawing circles around the columns is the enum organization.

It's all the same logic, just organized differently. enums make it easier to add functions but harder to add types; traits make it easier to add types but harder to add functions. And neither of those is fundamentally better than the other; you just have to decide which is less annoying for the situation you're in.

6 Likes