Sometimes defining a new struct is accompanied by a bit of boilerplate. For instance the default definition of Base.hash
is by object id. Often a hash
that is based on the object struture is preferable however. Similar for ==
.
StructHelpers aims to simplify the boilerplate required for such common tweaks.
struct S
a
b
end
@batteries S
@batteries S hash=false # don't overload `Base.hash`
@batteries S kwconstructor=true # add a keyword constructor
For all supported options and defaults, consult the docstring:
julia>?@batteries
- AutoHashEquals requires annotating the struct definition. This can be inconvenient if you want to annotate the definition with another macro as well.
- StructEquality is similar to this package.