How can I use comparison operators with custom struct

I am running into this error:

error: operator != not allowed for type ...

and I have no idea if there is an expected method I need to implement to be able to use != (and == etc) with my custom type.

Check out std.meta.eql() but be aware of the limitations:

You can use equality operators for packed structs. This is especially useful for simple wrapper types and only contain a single integer, as the packed nature doesn’t change anything in this case.

Zig does not have operator overloading, so it isn’t possible to re-define == and != for an arbitrary custom type.

You will instead use functions to do comparisons,

May I ask in which context you need an equality (or equivalence?) comparison?

Such a comparison could have different meanings:

  • equal memory representation
  • mathematically equal objects (e.g. two complex numbers that are mathematically equal)
  • values that represent the same object in reality (e.g. the same customer)
  • two values that belong to the same equivalence class (e.g. strings that are equal after case-folding)