StructHelpers.jl

Automate common struct definition boilerplate
Author jw3126
Popularity
13 Stars
Updated Last
3 Months Ago
Started In
June 2021

StructHelpers

Stable Dev Build Status Coverage

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.

Usage

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

Alternatives

  • 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.

Required Packages